1

The vue version is vue3. The axios version is 0.24.0. When I use this method to enable HTTPS, it noticed me that invalid cert.

    const axios = require('axios')
    const fs = require('fs')
    const https = require('https')
    import { Notify } from 'quasar';
    
    const httpsAgent = new https.Agent({
      ca: fs.readFileSync('xxx.pem')
    })
    
    axios.get('https://example.com:9500/xxx', { httpsAgent });

The cert is self-signed cert in PKCS8. And the error msg is

Failed to load resource: net::ERR_CERT_AUTHORITY_INVALID

I'm sure the cert is the server root CA. But is seems does't work in my code. I don't know what's wrong in my code or cert. Maybe need pkcs12 cert? Can somebody answer me. Thank a lot.

SNO
  • 793
  • 1
  • 10
  • 30
shulin01
  • 11
  • 2
  • It looks like you mix things together. What you showed is server side code, and the error is client side. – Estus Flask Nov 02 '21 at 07:12
  • The code and error are all client side. The server side is nginx and the client side is Vue in electron. The code in problem is the Vue code. @EstusFlask – shulin01 Nov 02 '21 at 09:57
  • See https://stackoverflow.com/help/how-to-ask . Nothing suggested that you use Electron. The code you posted is Node.js part of Electron app, it cannot cause this error because this is browser error (you don't have `fs`, etc in browser API). The error is caused by browser part of Electron app, which is not shown. The problem is NOT Vue itself because Vue doesn't care about how you do requests, you could reproduce it with plain Axios or fetch code. Please, provide https://stackoverflow.com/help/mcve that can reproduce the problem – Estus Flask Nov 02 '21 at 15:33

1 Answers1

0

https and fs are server-side libraries that you should not use with Quasar. On the client side you can use https simply removing them, the request will automatically go over https since it's the protocol you're specifying in the axios request:

const axios = require('axios')
import { Notify } from 'quasar';

axios.get('https://example.com:9500/xxx', { httpsAgent });

Enabling https on the server side is a totally different topic that has nothing to do with VueJS, and if you're using nginx it has nothing to do with javascript at all. https and fs would work if you used express, for example, as in this question: Enabling HTTPS on express.js

Lazza
  • 91
  • 4