mirror of
https://github.com/jxnblk/mdx-deck.git
synced 2024-11-13 06:19:41 +03:00
Specify host cli option
I normally do all my JS coding from my home server. This PR enables to to run the dev + hot client server correctly.
This commit is contained in:
parent
891afea260
commit
9845d08727
9
cli.js
9
cli.js
@ -30,6 +30,7 @@ const cli = meow(`
|
||||
|
||||
${chalk.gray('Dev server options')}
|
||||
|
||||
-h --host Dev server host
|
||||
-p --port Dev server port
|
||||
--no-open Prevent from opening in default browser
|
||||
|
||||
@ -51,6 +52,10 @@ const cli = meow(`
|
||||
type: 'string',
|
||||
alias: 'p'
|
||||
},
|
||||
host: {
|
||||
type: 'string',
|
||||
alias: 'h'
|
||||
},
|
||||
open: {
|
||||
type: 'boolean',
|
||||
alias: 'o',
|
||||
@ -83,6 +88,7 @@ const opts = Object.assign({
|
||||
globals: {
|
||||
FILENAME: JSON.stringify(path.resolve(doc))
|
||||
},
|
||||
host: 'localhost',
|
||||
port: 8080,
|
||||
outDir: 'dist',
|
||||
}, config, cli.flags)
|
||||
@ -163,7 +169,8 @@ switch (cmd) {
|
||||
dev = require('./lib/dev')
|
||||
dev(opts)
|
||||
.then(res => {
|
||||
const url = 'http://localhost:' + res.port
|
||||
const { address, port } = res.server.address()
|
||||
const url = 'http://' + address + ':' + res.port
|
||||
if (opts.open) open(url)
|
||||
log('listening on', chalk.magenta(url))
|
||||
})
|
||||
|
@ -126,7 +126,8 @@ const createConfig = (opts = {}) => {
|
||||
|
||||
const defs = Object.assign({}, opts.globals, {
|
||||
OPTIONS: JSON.stringify(opts),
|
||||
HOT_PORT: JSON.stringify(opts.hotPort)
|
||||
HOT_PORT: JSON.stringify(opts.hotPort),
|
||||
HOT_HOST: JSON.stringify(opts.host)
|
||||
})
|
||||
|
||||
config.plugins.push(
|
||||
|
@ -14,9 +14,11 @@ const devMiddleware = {
|
||||
|
||||
const start = async (opts = {}) => {
|
||||
const app = new Koa()
|
||||
opts.host = opts.host || 'localhost'
|
||||
opts.hotPort = await getPort()
|
||||
const hotClient = {
|
||||
port: opts.hotPort,
|
||||
host: opts.host,
|
||||
logLevel: 'error'
|
||||
}
|
||||
opts.dirname = opts.dirname || path.dirname(opts.entry)
|
||||
@ -34,7 +36,7 @@ const start = async (opts = {}) => {
|
||||
app.use(middleware)
|
||||
app.use(koaStatic(opts.dirname))
|
||||
|
||||
const server = app.listen(port)
|
||||
const server = app.listen(port, opts.host)
|
||||
return new Promise((resolve) => {
|
||||
middleware.devMiddleware.waitUntilValid(() => {
|
||||
resolve({ server, app, middleware, port })
|
||||
|
@ -60,7 +60,7 @@ const destroy = () => {
|
||||
document.body.removeChild(overlay)
|
||||
}
|
||||
|
||||
const ws = new WebSocket('ws://localhost:' + HOT_PORT)
|
||||
const ws = new WebSocket('ws://' + HOT_HOST + ':' + HOT_PORT)
|
||||
|
||||
ws.addEventListener('message', msg => {
|
||||
const data = JSON.parse(msg.data)
|
||||
|
Loading…
Reference in New Issue
Block a user