Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

feat(nitro)!: support overriding runtime config at a second level #3007

Closed
wants to merge 2 commits into from

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Jan 31, 2022

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Currently we can only override at the top level of runtime config. This now allows for overriding at a second (nested) level, for example, for modules which want to allow runtime configuration. At the same time, we also normalise to upper-snake-case (baseURL -> BASE_URL)

Consider this example:

export default defineNuxtConfig({
  publicRuntimeConfig: {
    // this previously required overriding with `baseURL=other node .output/server/index.mjs`
    // but is now normalised to `BASE_URL`
    baseURL: 'test',
    // this was previously impossible to override piece-meal
    // but can now be overriden with `MY_MODULE_SOME_KEY=false node .output/server/index.mjs`
    myModule: {
      someKey: true
    }
  }
})

Notes

  1. Note that we have special handling for app config - perhaps we can abandon this and default to (e.g.) APP_CDN_URL instead of NUXT_APP_CDN_URL?

    // Load dynamic app configuration
    const appConfig = _runtimeConfig.public.app
    appConfig.baseURL = process.env.NUXT_APP_BASE_URL || appConfig.baseURL
    appConfig.cdnURL = process.env.NUXT_APP_CDN_URL || appConfig.cdnURL
    appConfig.buildAssetsDir = process.env.NUXT_APP_BUILD_ASSETS_DIR || appConfig.buildAssetsDir

  2. If we're happy with this approach, I will update the documentation.

πŸ‘‰ Migration

  • If you are depending on overriding with a mixed-case environment variable, you should convert it to upper-snake-case instead (baseURL -> BASE_URL).

πŸ“ Checklist

  • I have updated the documentation accordingly.

@danielroe danielroe added enhancement New feature or request nitro labels Jan 31, 2022
@danielroe danielroe requested a review from pi0 January 31, 2022 11:13
@danielroe danielroe self-assigned this Jan 31, 2022
@netlify
Copy link

netlify bot commented Jan 31, 2022

βœ”οΈ Deploy Preview for nuxt3-docs ready!

πŸ”¨ Explore the source changes: 5a01b7a

πŸ” Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/61f7c52f7526820008515a4b

😎 Browse the preview: https://deploy-preview-3007--nuxt3-docs.netlify.app

@pi0
Copy link
Member

pi0 commented Feb 10, 2022

(PR is merged to nitropack relesing soon)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants