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
feat: add options in CLI to enable UNIX sockets #3812
Changes from all commits
45f4150
5b7e27a
90bd6c3
376dd35
8828878
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,13 @@ const argv = parseArgs(process.argv.slice(2), { | |
h: 'help', | ||
H: 'hostname', | ||
p: 'port', | ||
n: 'unix-socket', | ||
c: 'config-file', | ||
s: 'spa', | ||
u: 'universal' | ||
}, | ||
boolean: ['h', 's', 'u'], | ||
string: ['H', 'c'], | ||
string: ['H', 'c', 'n'], | ||
default: { | ||
c: 'nuxt.config.js' | ||
} | ||
|
@@ -38,6 +39,7 @@ if (argv.help) { | |
Options | ||
--port, -p A port number on which to start the application | ||
--hostname, -H Hostname on which to start the application | ||
--unix-socket, -u Path to a UNIX socket | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be --unix-socket, -n ? |
||
--spa Launch in SPA mode | ||
--universal Launch in Universal mode (default) | ||
--config-file, -c Path to Nuxt.js config file (default: nuxt.config.js) | ||
|
@@ -78,6 +80,6 @@ if (nuxt.options.render.ssr === true) { | |
} | ||
} | ||
|
||
const { port, host } = getLatestHost(argv) | ||
const { port, host, unix } = getLatestHost(argv) | ||
|
||
nuxt.listen(port, host) | ||
nuxt.listen(port, host, unix) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,23 +136,41 @@ module.exports = class Nuxt { | |
}) | ||
} | ||
|
||
listen(port = 3000, host = 'localhost') { | ||
listen(port = 3000, host = 'localhost', unix = undefined) { | ||
return new Promise((resolve, reject) => { | ||
const args = { exclusive: false } | ||
|
||
if (unix) { | ||
args.path = unix | ||
} else { | ||
args.port = port | ||
args.host = host | ||
} | ||
|
||
const server = this.renderer.app.listen( | ||
{ port, host, exclusive: false }, | ||
args, | ||
err => { | ||
/* istanbul ignore if */ | ||
if (err) { | ||
return reject(err) | ||
} | ||
|
||
const _host = host === '0.0.0.0' ? 'localhost' : host | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
'\n' + | ||
chalk.bgGreen.black(' OPEN ') + | ||
chalk.green(` http://${_host}:${port}\n`) | ||
) | ||
if (!unix) { | ||
const _host = host === '0.0.0.0' ? 'localhost' : host | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use consola for these calls. |
||
'\n' + | ||
chalk.bgGreen.black(' OPEN ') + | ||
chalk.green(` http://${_host}:${port}\n`) | ||
) | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
'\n' + | ||
chalk.bgGreen.black(' OPEN ') + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OPEN is not an appreciate badge. Maybe |
||
chalk.green(` unix+http://${unix}\n`) | ||
) | ||
} | ||
|
||
// Close server on nuxt close | ||
this.hook( | ||
|
@@ -171,7 +189,11 @@ module.exports = class Nuxt { | |
}) | ||
) | ||
|
||
this.callHook('listen', server, { port, host }).then(resolve) | ||
if (unix) { | ||
this.callHook('listen', server, { path: unix }); | ||
} else { | ||
this.callHook('listen', server, { port, host }).then(resolve) | ||
} | ||
} | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest
socket
for variable name. Unix is kind of not exactly related to sockets