mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 09:57:09 +00:00
Running on bare metal, 127.0.0.1 is a sensible choice of address to bind on, but that is not the case when running inside a container, so we add the ability to choose which IP to listen on. This can be given via the environment variable HTTP_HOST when starting the server or, if used as a module, as the second argument of the start(port, host, path) function.
37 lines
1.1 KiB
JavaScript
Executable File
37 lines
1.1 KiB
JavaScript
Executable File
#!/usr/bin/node
|
|
|
|
const { INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename);
|
|
|
|
async function main () {
|
|
// Check that we're running against the correct database version
|
|
const version = require('./lib/version');
|
|
INFO("Running version", await version.describe());
|
|
version.compatible()
|
|
.then( (versions) => {
|
|
const api = require('./api');
|
|
const ws = require('./ws');
|
|
|
|
const { fork } = require('child_process');
|
|
|
|
const port = process.env.HTTP_PORT || 3000;
|
|
const host = process.env.HTTP_HOST || "127.0.0.1";
|
|
const path = process.env.HTTP_PATH;
|
|
const server = api.start(port, host, path);
|
|
ws.start(server);
|
|
|
|
const eventManagerPath = [__dirname, "events"].join("/");
|
|
const eventManager = fork(eventManagerPath, /*{ stdio: 'ignore' }*/);
|
|
|
|
INFO("Versions:", versions);
|
|
|
|
process.on('exit', () => eventManager.kill());
|
|
})
|
|
.catch( ({current, wanted, component}) => {
|
|
console.error(`Fatal error: incompatible ${component} version ${current} (wanted: ${wanted})`);
|
|
ERROR(`Fatal error: incompatible ${component} version ${current} (wanted: ${wanted})`);
|
|
process.exit(1);
|
|
});
|
|
}
|
|
|
|
main();
|