Skip to content

Commit

Permalink
fix: broken after es module migration
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Dec 6, 2022
1 parent f39f185 commit c0a3b9c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/nanog → bin/nanog.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import gateway from '../index';
import gateway from '../index.js';
import minimist from 'minimist';

const base62 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -37,22 +39,22 @@ 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}`);
}

const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
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'));
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down

0 comments on commit c0a3b9c

Please sign in to comment.