Skip to content

Commit

Permalink
feat: redoc-cli add host option (#1598)
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Fürhoff authored Dec 31, 2021
1 parent ea8573d commit fb104e6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ YargsParser.command(
type: 'boolean',
});

yargs.option('h', {
alias: 'host',
type: 'string',
default: '127.0.0.1',
});

yargs.option('p', {
alias: 'port',
type: 'number',
Expand Down Expand Up @@ -93,7 +99,7 @@ YargsParser.command(
};

try {
await serve(argv.port as number, argv.spec as string, config);
await serve(argv.host as string, argv.port as number, argv.spec as string, config);
} catch (e) {
handleError(e);
}
Expand Down Expand Up @@ -167,7 +173,7 @@ YargsParser.command(
describe: 'ReDoc options, use dot notation, e.g. options.nativeScrollbars',
}).argv;

async function serve(port: number, pathToSpec: string, options: Options = {}) {
async function serve(host: string, port: number, pathToSpec: string, options: Options = {}) {
let spec = await loadAndBundleSpec(isURL(pathToSpec) ? pathToSpec : resolve(pathToSpec));
let pageHTML = await getPageHTML(spec, pathToSpec, options);
const server = createServer((request, response) => {
Expand Down Expand Up @@ -201,7 +207,7 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {

console.log();

server.listen(port, () => console.log(`Server started: http://127.0.0.1:${port}`));
server.listen(port, host, () => console.log(`Server started: http://${host}:${port}`));

if (options.watch && existsSync(pathToSpec)) {
const pathToSpecDirectory = resolve(dirname(pathToSpec));
Expand Down

0 comments on commit fb104e6

Please sign in to comment.