GithubHelp home page GithubHelp logo

Comments (4)

nicklpeterson avatar nicklpeterson commented on September 28, 2024 1

@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.

HofmannZ avatar HofmannZ commented on September 28, 2024

@nicklpeterson Thanks for the suggestion.

Would it be possible to:

  1. Create a utility that reads/parses the config file and save it to process.env.
  2. Run that util on server startup (like our makeEnvPublic) before configureRuntimeEnv.
  3. Then business as usual for accessing the variables.

What do you think?

from next-runtime-env.

nicklpeterson avatar nicklpeterson commented on September 28, 2024

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.

HofmannZ avatar HofmannZ commented on September 28, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.