Supporting binding server to specific hosts (#32)
Some checks failed
Node.js CI / build (22.x) (push) Has been cancelled

This commit is contained in:
Saana 2025-06-03 10:30:49 +02:00 committed by GitHub
parent 15666f8711
commit a50d5dd488
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -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}

View File

@ -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<void>;
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));