-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: add non invoking entry point
- Loading branch information
Showing
6 changed files
with
61 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/usr/bin/env node | ||
const { spawn } = require('child_process'); | ||
const path = require('path'); | ||
const mainPath = path.join(__dirname, '../dist/scrypted-main.js'); | ||
spawn('node', ['--expose-gc', mainPath], { stdio: 'inherit' }); | ||
require(mainPath); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import v8 from 'v8'; | ||
import vm from 'vm'; | ||
import process from 'process'; | ||
import semver from 'semver'; | ||
import { RPCResultError, startPeriodicGarbageCollection } from './rpc'; | ||
import { PluginError } from './plugin/plugin-error'; | ||
|
||
function start(mainFilename: string) { | ||
if (!global.gc) { | ||
v8.setFlagsFromString('--expose_gc') | ||
global.gc = vm.runInNewContext("gc"); | ||
} | ||
|
||
if (!semver.gte(process.version, '16.0.0')) { | ||
throw new Error('"node" version out of date. Please update node to v16 or higher.') | ||
} | ||
|
||
// Node 17 changes the dns resolution order to return the record order. | ||
// This causes issues with clients that are on "IPv6" networks that are | ||
// actually busted and fail to connect to npm's IPv6 address. | ||
// The workaround is to favor IPv4. | ||
process.env['NODE_OPTIONS'] = '--dns-result-order=ipv4first'; | ||
|
||
startPeriodicGarbageCollection(); | ||
|
||
if (process.argv[2] === 'child' || process.argv[2] === 'child-thread') { | ||
// plugins should never crash. this handler will be removed, and then readded | ||
// after the plugin source map is retrieved. | ||
process.on('uncaughtException', e => { | ||
console.error('uncaughtException', e); | ||
}); | ||
process.on('unhandledRejection', e => { | ||
console.error('unhandledRejection', e); | ||
}); | ||
|
||
const start = require('./scrypted-plugin-main').default; | ||
start(mainFilename); | ||
} | ||
else { | ||
// unhandled rejections are allowed if they are from a rpc/plugin call. | ||
process.on('unhandledRejection', error => { | ||
if (error?.constructor !== RPCResultError && error?.constructor !== PluginError) { | ||
console.error('wtf', error); | ||
throw error; | ||
} | ||
console.warn('unhandled rejection of RPC Result', error); | ||
}); | ||
|
||
const start = require('./scrypted-server-main').default; | ||
start(mainFilename); | ||
} | ||
} | ||
|
||
export default start; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,3 @@ | ||
import v8 from 'v8'; | ||
import vm from 'vm'; | ||
import process from 'process'; | ||
import semver from 'semver'; | ||
import { RPCResultError, startPeriodicGarbageCollection } from './rpc'; | ||
import { PluginError } from './plugin/plugin-error'; | ||
import start from './scrypted-main-exports'; | ||
|
||
if (!global.gc) { | ||
v8.setFlagsFromString('--expose_gc') | ||
global.gc = vm.runInNewContext("gc"); | ||
} | ||
|
||
if (!semver.gte(process.version, '16.0.0')) { | ||
throw new Error('"node" version out of date. Please update node to v16 or higher.') | ||
} | ||
|
||
// Node 17 changes the dns resolution order to return the record order. | ||
// This causes issues with clients that are on "IPv6" networks that are | ||
// actually busted and fail to connect to npm's IPv6 address. | ||
// The workaround is to favor IPv4. | ||
process.env['NODE_OPTIONS'] = '--dns-result-order=ipv4first'; | ||
|
||
startPeriodicGarbageCollection(); | ||
|
||
let startPromise: any; | ||
|
||
if (process.argv[2] === 'child' || process.argv[2] === 'child-thread') { | ||
// plugins should never crash. this handler will be removed, and then readded | ||
// after the plugin source map is retrieved. | ||
process.on('uncaughtException', e => { | ||
console.error('uncaughtException', e); | ||
}); | ||
process.on('unhandledRejection', e => { | ||
console.error('unhandledRejection', e); | ||
}); | ||
|
||
const start = require('./scrypted-plugin-main').default; | ||
startPromise = start(__filename); | ||
} | ||
else { | ||
// unhandled rejections are allowed if they are from a rpc/plugin call. | ||
process.on('unhandledRejection', error => { | ||
if (error?.constructor !== RPCResultError && error?.constructor !== PluginError) { | ||
console.error('wtf', error); | ||
throw error; | ||
} | ||
console.warn('unhandled rejection of RPC Result', error); | ||
}); | ||
|
||
const start = require('./scrypted-server-main').default; | ||
startPromise = start(__filename); | ||
} | ||
|
||
export default startPromise; | ||
start(__filename); |