Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use SSL with Vue CLI for local development?

I understand to use https with Vue CLI I can set "https: true" under devServer in a vue.config.js file, but I also need a self signed certificate.

I've tried generating a self signed one using OpenSSL and using the following in my vue.config.js file to target:

const fs = require('fs');

module.exports = {
    devServer: {
        port: '8081',
        https: {
            key: fs.readFileSync('./certs/server.key'),
            cert: fs.readFileSync('./certs/server.cert'),
        },
    },
};

Chrome confirms it's using my certificate but still shows https as "Not secure"

enter image description here

How can I make chrome assess my self signed certificate as secure when providing it via Vue CLI?

like image 984
blarg Avatar asked Apr 23 '19 14:04

blarg


People also ask

How do I use Vue https?

Run Vue. We can change the Vue dev server's config to serve the project over HTTPS rather than HTTP. To do that, we read the private key and certificate. And we set the URL to serve the project on. We read in the files and set them as the properties of the https property.

How do I run a Vue project on localhost?

Open in browser To view the project, open a tab and type http://localhost:3000 into the URL bar. That's the address that the Node server is listening to. You should now see this page, which is the basic structure of our project.


2 Answers

Simply enter this in your Chrome

chrome://flags/#allow-insecure-localhost

Set to Enabled, restart Chrome, and you're good to go.

like image 164
ssten Avatar answered Nov 15 '22 08:11

ssten


My problem was that everybody talks about putting the cert properties in the "https" child configuration node, but this doesn't work, you hve to put it in the devServer config node:

module.exports = {
devServer: {
    port: '8081',
    https: {
       key: fs.readFileSync('./certs/server.key'),
          --> this is WRONG

This is the correct way:

module.exports = {
  devServer: {
    disableHostCheck: true,
    port:8080,
    host: 'xxxxxx',
    https: true,
    //key: fs.readFileSync('./certs/xxxxxx.pem'),
    //cert: fs.readFileSync('./certs/xxxxxx.pem'),
    pfx: fs.readFileSync('./certs/xxxxxx.pfx'),
    pfxPassphrase: "xxxxxx",
    public: 'https://xxxxxx:9000/',
    https: true,
    hotOnly: false,
   }
}
like image 43
Emmanuel Avatar answered Nov 15 '22 07:11

Emmanuel