Can I serve `.env` files to Express?
So, in this repl, I want it so that if I'm the user, typing /.env
will serve the .env
file. But for other users, it should return a 403. But even Express doesn't know about my .env
file. How do I fix this?
Voters
Coder100 (16800)
HEY WHY ARE YOU NOT RESPONDING YOU MEANIE
RahulChoubey1 (136)
@Coder100 Sorry, was offline.
Coder100 (16800)
anyways ez
app.get("/.env", (req, res) => {
if (req.header("X-Replit-User-Name") == "WHATEVER UR NAME IS") res.type("text/plain").send("<INSERT THE ENV STUFF>");
else DO WHATEVER YOU WANT WITH NON USERS
});
19wintersp (1121)
@Coder100 header
is not a method of Express's Request
object, did you mean the get
method?
Coder100 (16800)
oh yeah oops @19wintersp
Coder100 (16800)
well u know that if you serve .env
the secret will no longer be public lol
RahulChoubey1 (136)
@Coder100 According to the code, it will be served only if I'm the one online. Else, it will return a 403 for obvious reasons.
first you need a sign in, i see that u use repl auth.
what you can do is something like
@EpicGamer007 I forgot about
process.env
lolget accepted
@RahulChoubey1 thx lol, i will delete the example repl i attached now