Comments (4)
@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
}
}
from next-runtime-env.
@nicklpeterson Thanks for the suggestion.
Would it be possible to:
- Create a utility that reads/parses the config file and save it to
process.env
. - Run that util on server startup (like our
makeEnvPublic
) beforeconfigureRuntimeEnv
. - Then business as usual for accessing the variables.
What do you think?
from next-runtime-env.
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.
from next-runtime-env.
@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:
- Parse a config file (and optionally configure its location.)
- Expose the parsed file to the browser.
- Provide a utility function (e.g.
config()
) that can read eighter for the window or from the process.
Looking forward to your input 🙂
from next-runtime-env.
Related Issues (20)
- questions about makeEnvPublic and EnvScript HOT 1
- is V1 support getStaticProps runtime variable ?
- Doesn't work when a page.tsx throws an unhandled exception. HOT 12
- Using Cypress will cause Hydration Problems. HOT 6
- Option to disable logging when using makeEnvPublic HOT 2
- Next-Cloudinary still cannot access NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME HOT 3
- lib doesn't work for next 14.2 HOT 3
- It does not read values when I reload a page of a subroute
- No longer works on Next.js 14 page router after v3.2.2 HOT 6
- Failed to compile on Next 14
- App Router Support without the need for `unstable_noStore`
- EnvScript works on client but not server HOT 3
- Window [__ENV] not being set in Header Script - Next 14.2.3 HOT 3
- Nextjs 14.2.5 (and older): notfound() / not-found client components don't have access to the environment variables. HOT 2
- Remove next and react from dependencies
- question about injecting environment variable thorugh docker run --env HOT 1
- How to access runtime env var in next.config.js HOT 1
- "Env" utility does not support custom variables HOT 2
- doesn't work with statically exported sites HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next-runtime-env.