Set run time parameters in next.js react app

I have a next.js React app that needs to load a set of parameters when it starts. These are basic items such as server addresses. I would like for the user to be able to enter a single word or phrase when docker runs the app and then have the app set those parameters based upon that word. A folder structure will be set up and the phrase entered by the user will dictate the parent folder from which these files are pulled.

  • Term 1
    • config.js
    • file1.json
    • file2.json
  • Term 2
    • config.js
    • file1.json
    • file2.json
  • Term 3
    • config.js
    • file1.json
    • file2.json

I have a config.json file and the plan was to take an environment variable and then use that variable within the relative address of an import statement to pull in the proper set of files and establish those config parameters. So, if the user entered "Term 1" then the config would be set based upon those files.

The problem is that the addresses within the import statements cannot contain variables. So, something like this is not valid:

import configLab from '../public/Builds/'+process.env.NEXT_PUBLIC_BUILD_LOC+'/config.js';

Creating a large variable and pulling properties based upon what is entered will not work. I need to be able to access folder files based upon the entered value.

Source: Docker Questions

LEAVE A COMMENT