-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support loading custom config files #91
Comments
@nicklpeterson Thanks for the suggestion. Would it be possible to:
What do you think? |
I don't think that will quite work for our use case. The config is an object the contains nested objects and arrays, so it's not something we want to parse into environment variables. Additionally we have multiple apps, so we'd ideally like something that can take a generic json or js config file and make it available at runtime. |
@nicklpeterson - That's fair. We could create something on top of our script solution (v3). We're more than happy to collaborate on your initiative. The general outline would be:
Looking forward to your input 🙂 |
@HofmannZ Yes - I think that would work! Are you thinking the new functions would be something like this? export interface ConfigScriptProps {
filePath: string;
nonce?: string;
}
export const ConfigScript: FC<ConfigScriptProps> = ({ filePath, nonce }) => {
noStore(); // Opt into dynamic rendering
// set nonce string (omitted for brevity)
// This value will be evaluated at runtime
const parsedConfig = config(filePath);
return <Script
nonce={nonceString}
dangerouslySetInnerHTML={{
__html: `window.__CONFIG__ = ${parsedConfig}`,
}}
/>
}; export const config = (filePath?: string = DEFAULT_PATH) => {
if (isBrowser()) {
return window.__CONFIG__;
} else {
// attempt to read from cache
// if cache is empty read from the file path
// parse and return object
}
} |
Thank you for this package it solves one consistent frustration I've had with Next.js!
We have a config file that gets written to the image at start up and we would like to make it available in the browser in the same way you have made the environment available. My idea is to add an additional public file
__CONFIG.js
that will add the config to the window and add a functionconfig()
that will return that config both client side and server side.Ideally this solution would support config files written in
json
,yml
,js
, orts
.I've only looked into the
v1.x.x
implementation so far as we are still on the page directory, but I suppose we could do something similar with providers forv2.x.x
.If you're interested I would be happy to contribute this feature.
The text was updated successfully, but these errors were encountered: