1

Is there any hook to enable https in VuePress dev server?

1. Current solution.

I directly add one line to node_modules/@vuepress/core/lib/node/dev/index.js. This works well, but nasty.

  createServer () {
    const contentBase = path.resolve(this.context.sourceDir, '.vuepress/public')

    const serverConfig = Object.assign({

      https: true, // <--- Added this line.

      disableHostCheck: true,
      compress: true,
      clientLogLevel: 'error',

2. Background

Because Chrome has changed it's security policy, CORS.

Image: "Mark cross-site cookies as Secure to allow them to be sent in cross-site requests."

3. What I've tried.

docs/.vuepress/config.js

  configureWebpack: (config, isServer) => {
    if (!config.devServer) {
      config.devServer = {}
    }
    Object.assign(config.devServer, {
      https: true,
    })
  }
module.exports = function (cli, options) {
  cli
    .command(`dev [targetDir]`, 'start development server')
    .option('-p, --port <port>', 'use specified port (default: 8080)')
    .option('-t, --temp <temp>', 'set the directory of the temporary file')
    .option('-c, --cache [cache]', 'set the directory of cache')
    .option('--host <host>', 'use specified host (default: 0.0.0.0)')
    .option('--no-cache', 'clean the cache before build')
    .option('--no-clear-screen', 'do not clear screen when dev server is ready')
    .option('--debug', 'start development server in debug mode')
    .option('--silent', 'start development server in silent mode')
    .option('--open', 'open browser when ready')
    .action((sourceDir = '.', commandOptions) => {
      const { debug, silent } = commandOptions

4. Related links.

nico
  • 31
  • 4
  • Welcome to StackOverflow community! Seems you have tried to format question yourself, it's.. well at least you tried. Just read this article (https://stackoverflow.com/editing-help) it will help you in future to handle Markdown. And don't forget to upvote users which provide useful information on your question and mark it as solved. – AlexZeDim Jul 19 '20 at 07:31
  • Copy that, sir :) – nico Jul 19 '20 at 07:48
  • Check this question, will help you: https://stackoverflow.com/questions/45807049/how-to-run-vue-js-dev-serve-with-https – Gabriel Willemann Jul 20 '20 at 18:35
  • 1
    Gabriel Willemann, thank you for your guidance. – nico Jul 21 '20 at 12:58

1 Answers1

2

Add the following settings to config.js.

//
// docs/.vuepress/config.js
//
module.exports = {

  devServer: {
    https: true
  },

}

Thank you for your guidance in many ways.

nico
  • 31
  • 4