and I’m creating a secret in the secret tab named
key = MESSAGE_STYLE
value = uppercase
It’s changing the value of response based upon the value of MESSAGE_STYLE in the local Environment of replit as it was asked in the challenge, but the test case is not passing.
Sorry, I didn’t quite get it, can you please elaborate.
When I’m changing the value of MESSAGE_STYLE on the /json route its changing into uppercase and lowercase depending upon the value in the secret tab.
Sure. Let us run through what the code/Node/Express app is doing:
You start your app (typically with a command like node ./server.js)
The code is run from top-to-bottom (once!!! - very important)
For a line like this:
let test = "hello";
app.get('/', (req, res) => {
res.json(test);
});
// -----------------------------------
// I am going to rewrite it like this:
function myCallback(req, res) {
res.json(test);
}
app.get('/', myCallback);
Now, the app object is defined to have a route handler (myCallback) which is executed (run) every time a GET request is made to the route /. According to your app this is transpiled to:
function myCallback(req, res) {
res.json("hello"); // This is "set in stone"
}
app.get('/', myCallback);
If I change test to equal "HELLO", nothing in my app definition is going to change, because the app was initially defined with "hello", and you are not redefining the whole app - just the variable test.
So, when (where) in the code execution would it make sense to re-define test?
What I understood is by changing the environment variable(secret in repl) won’t affect the previous app definition and if that’s the case how to reload or re-render the app again when the value of the environment variable is edited?
you need to consider where is the appropriate place to check the value of MESSAGE_STYLE, if you do it in the global scope it will be always the same.
If you do it in a function then the value will be that of when the function is called