From 292b5243c713d800a2b80b022bcfce0677e8b9a8 Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Thu, 4 Nov 2021 19:40:02 +0100 Subject: [PATCH] fix(nuxi): allow starting `nuxi dev` with self signed certificate (#1699) --- docs/content/1.getting-started/5.commands.md | 17 +++++++++++++++++ packages/kit/src/config/schema/server.ts | 8 ++++++++ packages/nuxi/src/commands/dev.ts | 15 ++++++--------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/docs/content/1.getting-started/5.commands.md b/docs/content/1.getting-started/5.commands.md index b29a190dae..e882ae83c6 100644 --- a/docs/content/1.getting-started/5.commands.md +++ b/docs/content/1.getting-started/5.commands.md @@ -31,6 +31,23 @@ npm run dev :: +To start Nuxt in development mode with HTTPS (self-signed certificate): + +::code-group + +```bash [Yarn] +yarn dev --https +``` + +```bash [NPM] +npm run dev -- --https +``` + +:: +::alert +`options.server` from `nuxt.config` is not supported. You can use `--port`, `--host`, `--https`, `--ssl-cert` and `--ssl-key` instead. +:: + ## Building for production To build your Nuxt application for production, run: diff --git a/packages/kit/src/config/schema/server.ts b/packages/kit/src/config/schema/server.ts index 6f0b52a3e0..77ff6bf522 100644 --- a/packages/kit/src/config/schema/server.ts +++ b/packages/kit/src/config/schema/server.ts @@ -14,10 +14,17 @@ export default { * } * } * ``` + * + * @version 2 + * + * @deprecated This option is ignored with Bridge and Nuxt 3 */ https: false, + /** @deprecated This option is ignored with Bridge and Nuxt 3 */ port: process.env.NUXT_PORT || process.env.PORT || process.env.npm_package_config_nuxt_port || 3000, + /** @deprecated This option is ignored with Bridge and Nuxt 3 */ host: process.env.NUXT_HOST || process.env.HOST || process.env.npm_package_config_nuxt_host || 'localhost', + /** @deprecated This option is ignored with Bridge and Nuxt 3 */ socket: process.env.UNIX_SOCKET || process.env.npm_package_config_unix_socket, /** @@ -28,5 +35,6 @@ export default { * Currently, only `total` is supported (which directly tracks the whole * time spent on server-side rendering. */ + /** @deprecated This option is ignored with Bridge and Nuxt 3 */ timing: (val: any) => val ? ({ total: true, ...val }) : false } diff --git a/packages/nuxi/src/commands/dev.ts b/packages/nuxi/src/commands/dev.ts index 5f5eae79f7..7ff7d4aa5e 100644 --- a/packages/nuxi/src/commands/dev.ts +++ b/packages/nuxi/src/commands/dev.ts @@ -13,25 +13,22 @@ import { defineNuxtCommand } from './index' export default defineNuxtCommand({ meta: { name: 'dev', - usage: 'npx nuxi dev [rootDir] [--clipboard] [--open, -o] [--port, -p] [--host, -h] [--ssl-cert] [--ssl-key]', + usage: 'npx nuxi dev [rootDir] [--clipboard] [--open, -o] [--port, -p] [--host, -h] [--https] [--ssl-cert] [--ssl-key]', description: 'Run nuxt development server' }, async invoke (args) { process.env.NODE_ENV = process.env.NODE_ENV || 'development' - const https = !!(args['ssl-cert'] && args['ssl-key']) const server = createServer() const listener = await server.listen({ clipboard: args.clipboard, open: args.open || args.o, port: args.port || args.p, hostname: args.host || args.h, - ...(https && { - https, - certificate: { - cert: args['ssl-cert'], - key: args['ssl-key'] - } - }) + https: Boolean(args.https), + certificate: (args['ssl-cert'] && args['ssl-key']) && { + cert: args['ssl-cert'], + key: args['ssl-key'] + } }) const rootDir = resolve(args._[0] || '.')