mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 09:57:09 +00:00
Allow setting IP to listen on.
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.
This commit is contained in:
@@ -322,15 +322,14 @@ app.disable('x-powered-by');
|
|||||||
app.enable('trust proxy');
|
app.enable('trust proxy');
|
||||||
INFO('trust proxy is ' + (app.get('trust proxy')? 'on' : 'off'));
|
INFO('trust proxy is ' + (app.get('trust proxy')? 'on' : 'off'));
|
||||||
|
|
||||||
const addr = "127.0.0.1";
|
|
||||||
|
|
||||||
if (!module.parent) {
|
if (!module.parent) {
|
||||||
var port = process.env.HTTP_PORT || 3000;
|
const port = process.env.HTTP_PORT || 3000;
|
||||||
var server = http.createServer(app).listen(port, addr);
|
const host = process.env.HTTP_HOST || "127.0.0.1";
|
||||||
|
var server = http.createServer(app).listen(port, host);
|
||||||
|
|
||||||
INFO('API started on port ' + port);
|
INFO('API started on port ' + port);
|
||||||
} else {
|
} else {
|
||||||
app.start = function (port = 3000, path) {
|
app.start = function (port = 3000, host = "127.0.0.1", path) {
|
||||||
|
|
||||||
var root = app;
|
var root = app;
|
||||||
if (path) {
|
if (path) {
|
||||||
@@ -339,7 +338,7 @@ if (!module.parent) {
|
|||||||
root.use(path, app);
|
root.use(path, app);
|
||||||
}
|
}
|
||||||
|
|
||||||
const server = http.createServer(root).listen(port, addr);
|
const server = http.createServer(root).listen(port, host);
|
||||||
if (server) {
|
if (server) {
|
||||||
// console.log(`API started on port ${port}, prefix: ${path || "/"}`);
|
// console.log(`API started on port ${port}, prefix: ${path || "/"}`);
|
||||||
INFO(`API started on port ${port}, prefix: ${path || "/"}`);
|
INFO(`API started on port ${port}, prefix: ${path || "/"}`);
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ async function main () {
|
|||||||
|
|
||||||
const { fork } = require('child_process');
|
const { fork } = require('child_process');
|
||||||
|
|
||||||
const server = api.start(process.env.HTTP_PORT || 3000, process.env.HTTP_PATH);
|
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);
|
ws.start(server);
|
||||||
|
|
||||||
const eventManagerPath = [__dirname, "events"].join("/");
|
const eventManagerPath = [__dirname, "events"].join("/");
|
||||||
|
|||||||
Reference in New Issue
Block a user