@spa-tools/runtime-config
Server-side Rendering (SSR)
If your SPA has to run in non-browser environments (e.g. for SSR) then the active hostname obviously cannot be automatically detected by the Runtime Config.
Consequently, to use Runtime Config server-side across mutliple environments will require some devops work to set the active environment at runtime. There is an option to manually set the active hostname, so from the Runtime Config perspective, it's very trivial. Of course the downside is you must set this across your devops builds using something akin to environment variables.
import { myAppConfigSet } from './myapp-domain-config';
// let's imagine that a quasi-environment variable is set
// and is currently embedded in the code
process.env.MYAPP_ACTIVE_HOSTNAME = 'myapp.com';
export const myAppRuntimeConfig = RuntimeConfig.initialize(myAppConfigSet, {
// for the correct config to be picked up during server-side
// rendering, you must manually set the active hostname, so
// here we are setting it to the value of the quasi env var
manualActiveHostname: process.env.MYAPP_ACTIVE_HOSTNAME,
});
console.log('The runtime config object we just initialized:');
console.log(myAppRuntimeConfig);