diff --git a/bin/nanog b/bin/nanog.js similarity index 93% rename from bin/nanog rename to bin/nanog.js index 33d5aa0..3ae9925 100755 --- a/bin/nanog +++ b/bin/nanog.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -import gateway from '../index'; +import gateway from '../index.js'; import minimist from 'minimist'; const base62 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; diff --git a/index.js b/index.js index bd7a9da..f20e5c2 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,8 @@ import proxy from 'express-http-proxy'; import rewrite from 'express-urlrewrite'; import yaml from 'js-yaml'; +const server = {}; + export default function gateway(configPath) { configPath = configPath || process.env.NANO_GATEWAY_CONFIG || 'config.yml'; @@ -37,7 +39,7 @@ export default function gateway(configPath) { } function showAddress(type) { - const bound = this[type].address(); + const bound = server[type].address(); console.log(`| ${type}://${bound.address}:${bound.port}`); } @@ -45,14 +47,14 @@ export default function gateway(configPath) { console.log(`nano-gateway v${pkg.version} started at:`); if (config.http || !config.https) { - this.http = app.listen(config.http.port || 8080, config.http.host, showAddress.bind(this, 'http')); + server.http = app.listen(config.http.port || 8080, config.http.host, showAddress.bind(this, 'http')); } if (config.https && config.https.key && config.https.cert) { const key = fs.readFileSync(config.https.key, 'utf8'); const cert = fs.readFileSync(config.https.cert, 'utf8'); const ca = config.https.ca ? fs.readFileSync(config.https.ca, 'utf8') : undefined; - this.https = https + server.http = https .createServer({key, cert, ca}, app) .listen(config.https.port || 8443, showAddress.bind(this, 'https')); } diff --git a/package.json b/package.json index 8d4a0aa..6e7e8dc 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,10 @@ "type": "module", "exports": "./index.js", "bin": { - "nanog": "./bin/nanog" + "nanog": "./bin/nanog.js" }, "scripts": { - "start": "./bin/nanog", + "start": "./bin/nanog.js", "lint:fix": "xo \"*.js\" \"bin/*\" --fix", "test": "xo \"*.js\" \"bin/*\"", "docker:build": "docker build -t nano-gateway .",