Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ docsify serve [path] [--open false] [--port 3000]
- Type: number
- Default: `3000`
- Description: Choose a listen port, defaults to `3000`.
- `--host` option:
- Shorthand: `-H`
- Type: string
- Default: `localhost`
- Description: Choose a host to bind to, defaults to `localhost`.

### `generate` command

Expand Down
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ docsify serve [path] [--open false] [--port 3000]
- Type: number
- Default: `3000`
- Description: Choose a listen port, defaults to `3000`.
- `--host` option:
- Shorthand: `-H`
- Type: string
- Default: `localhost`
- Description: Choose a host to bind to, defaults to `localhost`.

### `generate` command

Expand Down
10 changes: 9 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ require('yargs')
requiresArg: true,
type: 'number'
},
host: {
alias: 'H',
default: 'localhost',
desc: chalk.gray(y18n.__('serve.host')),
nargs: 1,
requiresArg: true,
type: 'string'
},
'livereload-port': {
alias: 'P',
default: 35729,
Expand All @@ -96,7 +104,7 @@ require('yargs')
type: 'string'
}
}),
handler: argv => run.serve(argv.path, argv.open, argv.port, argv.P, argv.i)
handler: argv => run.serve(argv.path, argv.open, argv.port, argv.host, argv.P, argv.i)
})
.command({
command: 'generate [path]',
Expand Down
7 changes: 4 additions & 3 deletions lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = function (
path,
openInBrowser,
port,
host,
livereloadPort,
indexName
) {
Expand Down Expand Up @@ -50,7 +51,7 @@ module.exports = function (
)
server.use(history({index: '/' + indexFileName}))
server.use(serveStatic(path, {index: indexName}))
server.listen(port)
server.listen(port, host)
lrserver
.createServer({
extraExts: ['md'],
Expand All @@ -60,15 +61,15 @@ module.exports = function (
.watch(path)

if (openInBrowser) {
open(`http://localhost:${port}`)
open(`http://${host}:${port}`)
}

const msg =
'\nServing ' +
chalk.green(`${path}`) +
' now.\n' +
'Listening at ' +
chalk.green(`http://localhost:${port}`) +
chalk.green(`http://${host}:${port}`) +
'\n'
console.log(msg)
})
Expand Down
1 change: 1 addition & 0 deletions tools/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"serve": "Lasse lokalen Server zur Webseitenvorschau laufen.",
"serve.open": "Dokumentation im Standardbrowser öffnen. Um explizit --open auf false zu setzen, kannst du --no-open verwenden.",
"serve.port": "Listen port.",
"serve.host": "Bind to host.",
"serve.indexname": "Custom filename instead of index.html to serve by default",
"livereload.port": "livereload Listen port.",
"usage": "Anwendung",
Expand Down
1 change: 1 addition & 0 deletions tools/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"serve": "Run local server to preview site.",
"serve.open": "Open docs in default browser. To explicitly set --open to false you may use --no-open.",
"serve.port": "Listen port.",
"serve.host": "Bind to host.",
"serve.indexname": "Custom filename instead of index.html to serve by default",
"generate": "Docsify's generators",
"generate.sidebar": "Generate sidebar file",
Expand Down
1 change: 1 addition & 0 deletions tools/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"serve": "本地预览",
"serve.open": "自动打开浏览器",
"serve.port": "设置端口",
"serve.host": "设置监听地址",
"serve.indexname": "自定义入口文件名,代替默认的 index.html",
"generate": "docsify 的生成器",
"generate.sidebar": "生成侧边栏文件",
Expand Down