Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WebSocket arg to allow manually setting port #5963

Merged
merged 7 commits into from
Jan 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 7 additions & 4 deletions packages/next/bin/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ const args = arg({
// Types
'--help': Boolean,
'--port': Number,
'--websocket': Number,
'--hostname': String,

// Aliases
'-h': '--help',
'-p': '--port',
'-w': '--websocket',
'-H': '--hostname'
})

Expand All @@ -31,9 +33,10 @@ if (args['--help']) {
You can set a custom folder in config https://github.com/zeit/next.js#custom-configuration.

Options
--port, -p A port number on which to start the application
--hostname, -H Hostname on which to start the application
--help, -h Displays this message
--port, -p A port number on which to start the application
--websocket, -w A port number on which to start dynamic entries websocket
--hostname, -H Hostname on which to start the application
--help, -h Displays this message
`)
process.exit(0)
}
Expand All @@ -54,7 +57,7 @@ if (!existsSync(join(dir, 'pages'))) {
}

const port = args['--port'] || 3000
startServer({dir, dev: true}, port, args['--hostname'])
startServer({dir, dev: true, wsPort: args['--websocket']}, port, args['--hostname'])
.then(async (app) => {
console.log(`> Ready on http://${args['--hostname'] || 'localhost'}:${port}`)
await app.prepare()
Expand Down
5 changes: 3 additions & 2 deletions packages/next/server/hot-reloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ function erroredPages (compilation, options = {enhanceName: (name) => name}) {
}

export default class HotReloader {
constructor (dir, { config, buildId } = {}) {
constructor (dir, { config, buildId, wsPort } = {}) {
this.buildId = buildId
this.wsPort = wsPort
this.dir = dir
this.middlewares = []
this.webpackDevMiddleware = null
Expand Down Expand Up @@ -174,7 +175,7 @@ export default class HotReloader {

this.wsPort = await new Promise((resolve, reject) => {
// create dynamic entries WebSocket
this.wss = new WebSocket.Server({ port: 0 }, function (err) {
this.wss = new WebSocket.Server({ port: this.wsPort || 0 }, function (err) {
if (err) {
return reject(err)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/next/server/next-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ErrorDebug from './error-debug'
export default class DevServer extends Server {
constructor (options) {
super(options)
this.wsPort = options.wsPort
this.renderOpts.dev = true
this.renderOpts.ErrorDebug = ErrorDebug
this.devReady = new Promise(resolve => {
Expand Down Expand Up @@ -52,7 +53,7 @@ export default class DevServer extends Server {
}

async prepare () {
this.hotReloader = new HotReloader(this.dir, { config: this.nextConfig, buildId: this.buildId })
this.hotReloader = new HotReloader(this.dir, { config: this.nextConfig, buildId: this.buildId, wsPort: this.wsPort })
await super.prepare()
await this.addExportPathMapRoutes()
await this.hotReloader.start()
Expand Down