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

feat: add options in CLI to enable UNIX sockets #3812

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion bin/common/utils.js
Expand Up @@ -38,6 +38,10 @@ exports.getLatestHost = argv => {
argv.hostname ||
process.env.HOST ||
process.env.npm_package_config_nuxt_host
const unix =
argv['unix-socket'] ||
process.env.UNIX_SOCKET ||
process.env.npm_package_config_unix_socket

return { port, host }
return { port, host, unix }
Copy link
Member

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

}
8 changes: 5 additions & 3 deletions bin/nuxt-start
Expand Up @@ -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'
}
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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)
Expand Down Expand Up @@ -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)
42 changes: 32 additions & 10 deletions lib/core/nuxt.js
Expand Up @@ -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(
Copy link

Choose a reason for hiding this comment

The 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 ') +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPEN is not an appreciate badge. Maybe LISTENING?

chalk.green(` unix+http://${unix}\n`)
)
}

// Close server on nuxt close
this.hook(
Expand All @@ -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)
}
}
)

Expand Down
10 changes: 5 additions & 5 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "nuxt",
"version": "1.4.0",
"version": "1.4.2",
"description": "A minimalistic framework for server-rendered Vue.js applications (inspired by Next.js)",
"contributors": [
{
Expand Down Expand Up @@ -107,12 +107,12 @@
"uglifyjs-webpack-plugin": "^1.1.8",
"upath": "^1.0.2",
"url-loader": "^0.6.2",
"vue": "^2.5.13",
"vue-loader": "13.7.0",
"vue": "^2.5.17",
"vue-loader": "^13.7.2",
"vue-meta": "^1.4.3",
"vue-router": "^3.0.1",
"vue-server-renderer": "^2.5.13",
"vue-template-compiler": "^2.5.13",
"vue-server-renderer": "^2.5.17",
"vue-template-compiler": "^2.5.17",
"vuex": "^3.0.1",
"webpack": "^3.11.0",
"webpack-bundle-analyzer": "^2.10.0",
Expand Down
24 changes: 12 additions & 12 deletions yarn.lock
Expand Up @@ -7867,9 +7867,9 @@ vue-hot-reload-api@^2.2.0:
version "2.2.4"
resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.2.4.tgz#683bd1d026c0d3b3c937d5875679e9a87ec6cd8f"

vue-loader@13.7.0:
version "13.7.0"
resolved "https://registry.yarnpkg.com/vue-loader/-/vue-loader-13.7.0.tgz#4d6a35b169c2a0a488842fb95c85052105fa9729"
vue-loader@^13.7.2:
version "13.7.2"
resolved "https://registry.yarnpkg.com/vue-loader/-/vue-loader-13.7.2.tgz#f633f6393e905ffd730400f03c99353618c08fe8"
dependencies:
consolidate "^0.14.0"
hash-sum "^1.0.2"
Expand Down Expand Up @@ -7897,9 +7897,9 @@ vue-router@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.1.tgz#d9b05ad9c7420ba0f626d6500d693e60092cc1e9"

vue-server-renderer@^2.5.13:
version "2.5.13"
resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.13.tgz#6a0d421a0fd3e2b7357b59495d744b7e9279d68e"
vue-server-renderer@^2.5.17:
version "2.5.17"
resolved "https://registry.yarnpkg.com/vue-server-renderer/-/vue-server-renderer-2.5.17.tgz#c1f24815a4b12a2797c154549b29b44b6be004b5"
dependencies:
chalk "^1.1.3"
hash-sum "^1.0.2"
Expand All @@ -7917,9 +7917,9 @@ vue-style-loader@^3.0.0:
hash-sum "^1.0.2"
loader-utils "^1.0.2"

vue-template-compiler@^2.5.13:
version "2.5.13"
resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.13.tgz#12a2aa0ecd6158ac5e5f14d294b0993f399c3d38"
vue-template-compiler@^2.5.17:
version "2.5.17"
resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.5.17.tgz#52a4a078c327deb937482a509ae85c06f346c3cb"
dependencies:
de-indent "^1.0.2"
he "^1.1.0"
Expand All @@ -7928,9 +7928,9 @@ vue-template-es2015-compiler@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.6.0.tgz#dc42697133302ce3017524356a6c61b7b69b4a18"

vue@^2.5.13:
version "2.5.13"
resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.13.tgz#95bd31e20efcf7a7f39239c9aa6787ce8cf578e1"
vue@^2.5.17:
version "2.5.17"
resolved "https://registry.yarnpkg.com/vue/-/vue-2.5.17.tgz#0f8789ad718be68ca1872629832ed533589c6ada"

vuex@^3.0.1:
version "3.0.1"
Expand Down