Micheal J. Roberts
Micheal J. Roberts

Reputation: 4170

nuxt.js Configuring Localhost https server (but not in production)

I have the following server configuration setup for my nuxt.js project:

import path from 'path'
import fs from 'fs'

export default {
  ...
  
  server: {
    https: {
      key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
      cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
    }
  }
  
  ...
}

This all works great in local development - but we deploy to Netlify. And it causes issues when deployed in production.

So, I was wondering, what is the "trick" to turning certain configurations on and off in production inside nuxt.config.js...?

Upvotes: 1

Views: 1413

Answers (1)

kissu
kissu

Reputation: 46696

You could use some conditionnal like

baseURL: process.env.NODE_ENV === 'production' ? 'https://nuxtjs.org' : 'https://dev.nuxtjs.org'

or env variables, having differents values in .env and in your Netlify dashboard.

Here is an interesting article on runtime env variables: https://nuxtjs.org/blog/moving-from-nuxtjs-dotenv-to-runtime-config/

And here is the official documentation about env variables: https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-env/

Upvotes: 1

Related Questions