Skip to content

Commit

Permalink
Add cli option to specify host
Browse files Browse the repository at this point in the history
  • Loading branch information
nisargjhaveri committed Aug 21, 2024
1 parent b978541 commit e56266f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/server/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ export const commandServer = {
nargs: 1,
type: 'number',
})
.option('host', {
describe: 'host to bind the server to',
nargs: 1,
type: 'string',
})
.option('password', {
describe: 'specify password required to connect',
type: 'string',
nargs: 1
})
.group(['port', 'password'], "Server Options:")
.group(['port', 'host', 'password'], "Server Options:")
.option('key', {
describe: 'file containing RSA private key',
requiresArg: true
Expand All @@ -47,14 +52,14 @@ export const commandServer = {
.group(['key', 'cert'], "HTTPS Options:")
.strict()
},
handler: (args: {port?: number, key?: string, cert?: string, password?: string}) => {
handler: (args: {port?: number, host?: string, key?: string, cert?: string, password?: string}) => {
const useHttps = !!(args.key && args.cert);
const httpsOptions = useHttps ? {
key: fs.readFileSync(args.key),
cert: fs.readFileSync(args.cert)
} : undefined;

const listenOptions = { port: args.port };
const listenOptions = { port: args.port, host: args.host };

new Server(listenOptions, httpsOptions, args.password).start();
}
Expand Down

0 comments on commit e56266f

Please sign in to comment.