From c7edc49d77e1c1b37e10bf4da8f6b4f8ccc460e1 Mon Sep 17 00:00:00 2001 From: Will Soto Date: Sat, 5 May 2018 09:52:21 -0400 Subject: [PATCH] feat(serve): add support for `--cert` and `--key` Closes #1226 Signed-off-by: Will Soto --- packages/@vue/cli-service/lib/commands/serve.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/@vue/cli-service/lib/commands/serve.js b/packages/@vue/cli-service/lib/commands/serve.js index 3eed23c4ef..e77cbb2a3c 100644 --- a/packages/@vue/cli-service/lib/commands/serve.js +++ b/packages/@vue/cli-service/lib/commands/serve.js @@ -19,7 +19,9 @@ module.exports = (api, options) => { '--mode': `specify env mode (default: development)`, '--host': `specify host (default: ${defaults.host})`, '--port': `specify port (default: ${defaults.port})`, - '--https': `use https (default: ${defaults.https})` + '--https': `use https (default: ${defaults.https})`, + '--cert': 'Specify a cert to enable https. Must be paired with a key', + '--key': 'Specify a key to enable https. Must be paired with a cert' } }, async function serve (args) { info('Starting development server...') @@ -78,9 +80,20 @@ module.exports = (api, options) => { // resolve server options const useHttps = args.https || projectDevServerOptions.https || defaults.https const host = args.host || process.env.HOST || projectDevServerOptions.host || defaults.host + const cert = args.cert || process.env.CERT || projectDevServerOptions.cert || false + const key = args.key || process.env.KEY || projectDevServerOptions.key || false portfinder.basePort = args.port || process.env.PORT || projectDevServerOptions.port || defaults.port const port = await portfinder.getPortPromise() + let https = useHttps + + if (cert && key) { + https = { + cert: cert, + key: key + } + } + const urls = prepareURLs( useHttps ? 'https' : 'http', host, @@ -108,7 +121,7 @@ module.exports = (api, options) => { ? false : { warnings: false, errors: true } }, projectDevServerOptions, { - https: useHttps, + https: https, proxy: proxySettings, before (app) { // launch editor support.