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
Project ID:
N/A
n/a
holdup
7a770d54-1044-4ce1-a174-45b1edfcd4f8
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-variablesim 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 anythinggetting this in console tho
probably my answer
think you need to research how to use environment variables with frontend sites
your absolutly right frontend is not my strong side
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
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 buildyou really shouldn't be running preview on railway
how else should i be starting it after build?
like how this template does
https://github.com/brody192/vite-react-template
show me your service variables please?
this is what it requests to
i mean you blurred out the url, so i dont know if thats correct or not
one starts with api, the other is ui
its not a secret, so theres no need for blur
they are 2 different links
what im doing wrong atp
never had this happen
common problem, google has answers
how is that a common problem
my env variable is not what i put it as
send again but not blurred please
okay now show me a console log output for that environment variable
^
i have researched i dont understand whats wrong lmao
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
im working on it lol
that was mid commit was doing something else
doesnt
vite build
output to dist
?
but you have set serve to serve the .svelte-kit
folderno not for sveltekit, everything goes to
.svelte-kit
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 frontendappreciate it, let me test that out
that does work, thanks! very new to frontend and that is a mistake i definitely wont make again
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
all good, you learn something new everyday
would you like me to create a pr to add a start command?
because running preview mode is still undesirable
what would you reccoment for svelte? i tried serve but couldnt find the directory it wanted me to view
check the pull requests
👍 trying it now
looks like it works, thanks
have you removed all custom commands that you have set in the service settings?
i just have
yarn run build
and yarn run start
, thats all i should have right?screenshot please
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