diff --git a/config/config-example.js b/config/config-example.js index d16d486..257243b 100644 --- a/config/config-example.js +++ b/config/config-example.js @@ -133,6 +133,13 @@ exports.crashguardemail = null; */ exports.ssl = null; +/** + * Address to bind to. + * Leaving it as `undefined` will result in binding to `0.0.0.0`. + * @type {undefined | string} + */ +exports.bindaddress = undefined; + /** * Port to listen on. * @type {number} diff --git a/src/server.ts b/src/server.ts index 92d6025..c336172 100644 --- a/src/server.ts +++ b/src/server.ts @@ -324,15 +324,17 @@ export const SimServers = new class SimServersT { export class Server { server: http.Server; httpsServer: https.Server | null; + host: string; port: number; awaitingEnd?: () => void; closing?: Promise; activeRequests = 0; - constructor(port = (Config.port || 8000)) { + constructor(port = (Config.port || 8000), host = (Config.bindaddress || "0.0.0.0")) { + this.host = host; this.port = port; this.server = http.createServer((req, res) => void this.handle(req, res)); - this.server.listen(port); + this.server.listen(port, host); this.httpsServer = null; if (Config.ssl) { this.httpsServer = https.createServer(Config.ssl, (req, res) => void this.handle(req, res));