How to run NUXT (npm run dev) with HTTPS in localhost?

前端 未结 3 1239
野的像风
野的像风 2020-12-15 08:20

EDIT: Updated the text in general to keep it shorter and more concise.

I am trying to configure HTTPS when I run npm run dev so I can t

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-15 08:40

    You must follow the doc spec here https://nuxtjs.org/api/configuration-server/#example-using-https-configuration, BUT you must add code in the server/index.js file, otherwise it won’t work at all.

    So in the server/index.js add const https = require('https') at the top and replace :

    app.listen(port, host)
      consola.ready({
        message: `Server listening on http://${host}:${port}`,
        badge: true
      })
    

    With

    https.createServer(nuxt.options.server.https, app).listen(port, host);
    

    And now it’s working!

提交回复
热议问题