env vite reactjs
Hey guys, i tried everything but i cannot get my env variables on my vite app.
here my track conversation:
https://help.railway.app/questions/vite-envs-with-reactjs-49ea0fd4
i also tried the nixpack.toml way, but did not work
Railway Help Station
VITE envs with REACTJS
idk why it doesn't take my env variablesso i have my .env with:VITE_FIREBASE_API_KEY_O=TOKEN
VITE_FIREBASE_AUTHDOMAIN=TOKENand my railway have env setup the same..i tried to get them in a lot of ways:- by simply using import.meta.env.VITE_FIREBASE_API_KEY_O- or in my vite.config.jsimport { defineConfig, loadEnv } from "vite";
import react from "...
25 Replies
Project ID:
0bebe0c6-57e2-4755-93c3-ce48f433731b
0bebe0c6-57e2-4755-93c3-ce48f433731b
hey, please dont cross post, if you feel like i have dropped the ball in your thread, feel free to bump it, but please dont create duplicate threads.
okok, i just posted here because i saw quick answers, any help with that thread?
im typing in that thread as we speak, but you are right, discord is a more chat oriented place, if you want to swap to discrd for support that is fine with me
let is swap
do you think i need to rewrite everything?
well currently your build is failing, you should look at your build logs and make the needed fixes to at least get it to build before we worry about environment variables
it is failing because i am trying to fix that errors
sounds good, please get your build building before we worry about environment variables
hey @Brody now is up, i think i made a success deploy with caddy i had problem to understand on how i need to place the endpoints as i did in my vite.config.js before
endpoints?
these endpoints:
in this case it understand base_url/auth
imo, using a proxy here is a terrible practice, ive only ever seen user's have trouble with it when they go to run their app in a production environment.
you can rip all the proxy stuff out, then for example, instead of calling
/auth
you call <backend url from environment variable> + "/auth"
i have problems gettings envs..
and now i cannot reach the endpoind after deploy, i have 502 error
here my actual Docker file
Here my actual caddyfile:
This is my env port setup on railway:
@Brody and this have no sense:
when i run my docker container in localhost i see
VITE_FIREBASE_API_KEY_O
and VITE_USER_QUEUE_REGISTRATION
but not my VITE_ENDPOINT_API
(it is undefined)can you send your vite config again
is this one:
i think it is sad because in localhost is working and in production not..
as previously mentioned, please remove the proxy stuff
and also the define stuff while you're at it
Hey @Brody many thanks for your patience,
i still have my envs undefined ..
but you know what God is good also while my envs are undefined
send me your new config file
@Brody fixed, the problem were how i was pulling envs so the process is:
- make sure it is taking the right .env file
- add envs in your service in railway
- add them also as ENV & ARG
- depending on your webserver pull envs (process.env, import.meta.env,....)
thank you brother
you arent using .env files in prod right?
yes i am using them
and i was using them
please never use .env files in prod, thats a horrible practice