env variable problems

i am trying to get an env variable i set on my project but for some reason its giving me a whole different url (my ui) with /undefined at the end, honestly have no idea why thats happening this is the code where i get the env var https://github.com/subtosharki/inventory-ui/blob/master/src/lib/constants.ts
GitHub
inventory-ui/constants.ts at master · subtosharki/inventory-ui
the ui to my inventory system. Contribute to subtosharki/inventory-ui development by creating an account on GitHub.
46 Replies
Percy
Percy2y ago
Project ID: N/A
sharki
sharkiOP2y ago
n/a holdup 7a770d54-1044-4ce1-a174-45b1edfcd4f8
Brody
Brody2y ago
try process.env.API_URL instead? but RAILWAY_STATIC_URL is automatically injected, so you might have better luck using that https://docs.railway.app/develop/variables#railway-provided-variables
sharki
sharkiOP2y ago
im trying to get my api url for my client but its not coming through, using RAILWAY_STATIC_URL would give me my client url. ill try that way but i dont think that would do anything
sharki
sharkiOP2y ago
sharki
captured using file.glass
sharki
sharkiOP2y ago
getting this in console tho probably my answer
Brody
Brody2y ago
think you need to research how to use environment variables with frontend sites
sharki
sharkiOP2y ago
your absolutly right frontend is not my strong side
Brody
Brody2y ago
I haven't use environment variables in frontend code, so unfortunately I'm of no real help there but I'd like to inquire, what have you defined your start command as? since I don't see a start command in package.json
sharki
sharkiOP2y ago
i just changed it to the proper code for frontend import.meta.env.API_URL and im still getting the url of my client (that project) it builds using build and then preview is vites way of starting the build
Brody
Brody2y ago
you really shouldn't be running preview on railway
sharki
sharkiOP2y ago
how else should i be starting it after build?
Brody
Brody2y ago
like how this template does https://github.com/brody192/vite-react-template show me your service variables please?
sharki
sharkiOP2y ago
sharki
captured using file.glass
sharki
sharkiOP2y ago
sharki
sharkiOP2y ago
this is what it requests to
Brody
Brody2y ago
i mean you blurred out the url, so i dont know if thats correct or not
sharki
sharkiOP2y ago
one starts with api, the other is ui
Brody
Brody2y ago
its not a secret, so theres no need for blur
sharki
sharkiOP2y ago
they are 2 different links what im doing wrong atp never had this happen
Brody
Brody2y ago
common problem, google has answers
sharki
sharkiOP2y ago
how is that a common problem my env variable is not what i put it as
Brody
Brody2y ago
send again but not blurred please
sharki
sharkiOP2y ago
Brody
Brody2y ago
okay now show me a console log output for that environment variable
sharki
sharkiOP2y ago
sharki
sharkiOP2y ago
sharki
captured using file.glass
Brody
Brody2y ago
^
sharki
sharkiOP2y ago
i have researched i dont understand whats wrong lmao
Brody
Brody2y ago
more research, ive seen people have this issue before and once they fixed it, they said it was pretty straight forward good attempt lol https://github.com/subtosharki/inventory-ui/blob/eb774bfa39ebb284c7eb9331ec75d886902bf151/package.json#L12
sharki
sharkiOP2y ago
im working on it lol that was mid commit was doing something else
Brody
Brody2y ago
doesnt vite build output to dist? but you have set serve to serve the .svelte-kit folder
sharki
sharkiOP2y ago
no not for sveltekit, everything goes to .svelte-kit
Brody
Brody2y ago
figured it out you need to prefix the variables with VITE_ or else they will not get exported I have confirmed this with your codebase and have been able to pass variables to the frontend
sharki
sharkiOP2y ago
appreciate it, let me test that out that does work, thanks! very new to frontend and that is a mistake i definitely wont make again
Brody
Brody2y ago
also I was very very wrong about using serve too go back to using preview, and I will create a PR to fix that after dinner I apologize
sharki
sharkiOP2y ago
all good, you learn something new everyday
Brody
Brody2y ago
would you like me to create a pr to add a start command? because running preview mode is still undesirable
sharki
sharkiOP2y ago
what would you reccoment for svelte? i tried serve but couldnt find the directory it wanted me to view
Brody
Brody2y ago
check the pull requests
sharki
sharkiOP2y ago
👍 trying it now looks like it works, thanks
Brody
Brody2y ago
have you removed all custom commands that you have set in the service settings?
sharki
sharkiOP2y ago
i just have yarn run build and yarn run start, thats all i should have right?
Brody
Brody2y ago
screenshot please
sharki
sharkiOP2y ago
sharki
captured using file.glass
Brody
Brody2y ago
yeah you can remove both of them railway will use the scripts defined in the package.json, so there's no need to set those two commands in the service settings
Want results from more Discord servers?
Add your server