question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot set runtime config options in the `listen` hook

See original GitHub issue

Environment

Nuxt CLI v3.0.0-27404337.c9c0171 23:24:46 RootDir: /Volumes/Samsung_T5/GitHub/mai-attire 23:24:47 Nuxt project info: 23:24:47


  • Operating System: Darwin
  • Node Version: v14.18.2
  • Nuxt Version: 3.0.0-27404337.c9c0171
  • Package Manager: yarn@1.22.17
  • Bundler: Vite
  • User Config: privateRuntimeConfig, buildModules, googleFonts, css, vite, ngrok
  • Runtime Modules: -
  • Build Modules: ~/modules/google-fonts, ~/modules/ngrok

Reproduction

nuxt.hook('listen', () => {
  const url = 'my.url.com'
  nuxt.options.publicRuntimeConfig.ngrok = { url };
})
import config from "#config";

export default class ServerMiddlewarUtils {
  constructor() {
    console.log("config", config);
  }
}

Describe the bug

When creating a module, the only way I can see to set the runtime configs is as shown above - this was also how modules used to do it as well such as the ngrok module.

The new value is not available when importing #config in server middleware.

Additional context

No response

Logs

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lewebsimplecommented, Jul 6, 2022

Isn’t the listen hook only available in development mode ?

1reaction
danielroecommented, Apr 14, 2022

By this point in the server lifecycle, we have already passed runtime configuration to nitro, so changing top-level items doesn’t take effect (but modifying nested objects should work fine): https://stackblitz.com/edit/github-bsr21s.

However, for a dev module, you should be careful not to set runtimeConfig at build-time or the configuration will persist into the built server. It’s also limited to things that can be serialized - so no functions in runtimeConfig, for example.

Finally, it’s also possible to add a template and access this within your serverMiddleware: https://stackblitz.com/edit/github-bsr21s-bf23tt.

Note: We should consider which of these options we recommend (if any) and document this in the module authors guide. cc: @pi0 @clemcode

Read more comments on GitHub >

github_iconTop Results From Across the Web

Load custom configuration runtime - node.js
Currently I am trying to use a hook to solve this, but I am not really sure on how to actually set the...
Read more >
Runtime configuration settings
Runtime configuration settings. The RuntimeConfig.xml file contains user configuration settings for Pega Robot Runtime and Agile Desktop.
Read more >
NET Runtime configuration settings
Learn how to configure the .NET runtime using configuration settings.
Read more >
cri-o/crio.conf.5.md at main
RUNTIME TABLE. The crio.runtime table contains settings pertaining to the OCI runtime used and options for how to set up and manage the...
Read more >
Advanced configuration - GitLab Docs
These settings are global. They apply to all runners. Setting, Description. concurrent, Limits how many jobs can run concurrently, across all ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found