Correct environment variables

environment variables DATABASE_URL REDIS_URL Is this correct or should I specify the value from the database and redis ?
No description
85 Replies
Percy
Percy9mo ago
Project ID: 8b1e4ae6-f221-4948-a158-23868f94c7db
testerOne
testerOneOP9mo ago
8b1e4ae6-f221-4948-a158-23868f94c7db
Fragly
Fragly9mo ago
that looks correct to me, although one thing to keep in mind is that you're using the public url of the databases which will result in egress usage, you'd typically want to use the private_url when possible but this should work nonetheless
testerOne
testerOneOP9mo ago
I understand well, it can show that this is a link to the created database. Please tell me, I can’t change the region in any way? I need to be in Asia because I’m from Kazakhstan. I'm not going to change it after that.
No description
Fragly
Fragly9mo ago
yea, unfortunately regions is a feature limited to Pro Plan at the moment
testerOne
testerOneOP9mo ago
OK ! I hope this doesn't affect the speed too much. In any case, I'll test it for now. Perhaps in September I will be able to develop an application-website forum and then I will choose a plan and choose Asia for myself)
Fragly
Fragly9mo ago
Sounds good, best of luck
testerOne
testerOneOP9mo ago
Last stupid question 😄 How can I navigate the path now? Previously, when I was on localhost, I wrote localhost:7001 .. now I don’t see a path that I can take
Fragly
Fragly9mo ago
if you want to expose your service to the internet then you can go to your service settings and generate a domain for it ( or add a custom domain ) once you've done that then your app should be live on that domain although one thing to note is that your app should be listening on the port that Railway provides which can be found in an environment variable called PORT in nodejs you can get the port by doing something like this:
const port = process.env.PORT || 3000
const port = process.env.PORT || 3000
testerOne
testerOneOP9mo ago
ok, I think I did everything according to the guide, but so far I don’t see anything on the link
No description
Fragly
Fragly9mo ago
mind sharing your link?
testerOne
testerOneOP9mo ago
oh everything worked! you just had to wait! THANK YOU VERY MUCH ! I'M SO HAPPY ! I WISH YOU ALL THE KINDEST AND BEST THIS DAY AND THIS YEAR! THIS IS JUST GORGEOUS! THANK YOU ! Now works https://stroyberymedusabackend-production.up.railway.app/app/login
Fragly
Fragly9mo ago
oh, awesome!
testerOne
testerOneOP9mo ago
Can I ask for more? Am I doing everything right? More likely, what am I doing wrong? I want to install a new user for the admin panel
No description
No description
testerOne
testerOneOP9mo ago
i use - railway login -railway link
Fragly
Fragly9mo ago
for the first one, you're supposed to run railway link, this will lead you through a few steps where you can select which project to use the second one, idk, i've never used the medusa CLI before ( i didn't even know that existed )
testerOne
testerOneOP9mo ago
That correct ?
No description
Fragly
Fragly9mo ago
seems like you're on the right path oh hold on though, what do you mean by this? " I want to install a new user for the admin panel"
testerOne
testerOneOP9mo ago
Now if I write ~railway shell~, will I be inside cmd railway?
Fragly
Fragly9mo ago
Railway doesn't allow for SSH access unfortunately there's no way to directly interact with your container
testerOne
testerOneOP9mo ago
In Medusa you need to write the command npx medusa user --email [email protected] --password supersecret in cmd so you can log into the admin panel I can’t figure out how to connect to the cmd of my project to write this command
Fragly
Fragly9mo ago
even if you could, it wouldn't be much help, your app doesn't run in a traditional VM on Railway but rather an ephimeral container so anything you do in that container is going to be wiped when you redeploy your project
Fragly
Fragly9mo ago
ooh i see, sorry I'm unfamiliar with medusa, let me skim through the docs real quick it creates a new user on the database, that makes sense
I can’t figure out how to connect to the cmd of my project to write this command
On railway there isn't really anyway to run commands in the container of your project railway run runs a command locally but with the same env as your railway project
testerOne
testerOneOP9mo ago
I don't understand, did I miss something? It's like it goes into the railroad, but then it does it locally on my PC..
No description
Fragly
Fragly9mo ago
yea, like I said here, railway run runs a command locally but with the same environment variables as your railway project
testerOne
testerOneOP9mo ago
How can I transfer user data to log in? https://discord.com/channels/713503345364697088/1097967314655268925/1098005657258578070 There was a similar task here, but he somehow managed it, as I understand it
Fragly
Fragly9mo ago
yea right now I'm trying to figure out why you're getting this error
No description
Fragly
Fragly9mo ago
do you have a database connected to your medusa service?
testerOne
testerOneOP9mo ago
i think so
No description
testerOne
testerOneOP9mo ago
No description
Fragly
Fragly9mo ago
dang yea I'm completely out of ideas, I did find https://github.com/medusajs/medusa/issues/4449 although the solutions there seems like workarounds instead of actual solutions, although maybe some of the workarounds will work for you I have no idea why you're getitng that error, it's an issue with Medua CLI though
testerOne
testerOneOP8mo ago
Thank u 3 @Fragly hi Can i asq u again pls?
Fragly
Fragly8mo ago
about this same error?
testerOne
testerOneOP8mo ago
Maybe. Please tell me this column, is it related to the fact that I connected the database incorrectly? This is the value for 2 or 3 days Seems strangely big
No description
testerOne
testerOneOP8mo ago
No description
Fragly
Fragly8mo ago
Definitally seems like it yes, do you need help correctly setting it up?
testerOne
testerOneOP8mo ago
40 gb 2 day.. yes please
Fragly
Fragly8mo ago
Alright, mind opening your own thread? ooh wait this is your thread 🤣
testerOne
testerOneOP8mo ago
:salute:
Fragly
Fragly8mo ago
In the service you're connecting Postgres to, in this case "stroyberyMedusa..." could you go verify that your database variables still look like this?
No description
testerOne
testerOneOP8mo ago
DATABASE_TYPE=postgres PGHOST=${{Postgres.PGHOST}} PGPASSWORD=${{Postgres.PGPASSWORD}} PGPORT=${{Postgres.PGPORT}} PGUSER=${{Postgres.PGUSER}} PORT=9000 REDISHOST=${{Redis.REDISHOST}} REDISPASSWORD=${{Redis.REDISPASSWORD}} REDISPORT=${{Redis.REDISPORT}} REDISUSER=${{Redis.REDISUSER}} REDIS_URL=${{Redis.REDIS_URL}} CACHE_REDIS_URL=${{Redis.REDIS_URL}} STORE_CORS=/vercel.app$/ ADMIN_CORS=/vercel.app$/ MEDUSA_BACKEND_URL=https://stroyberymedusabackend-production.up.railway.app DATABASE_URL=${{Postgres.DATABASE_URL}}
Fragly
Fragly8mo ago
oh, cool, that works too
testerOne
testerOneOP8mo ago
I'm not sure I need that much
Fragly
Fragly8mo ago
DATABASE_TYPE=postgres
PGHOST=${{Postgres.PGHOST}}
PGPASSWORD=${{Postgres.PGPASSWORD}}
PGPORT=${{Postgres.PGPORT}}
PGUSER=${{Postgres.PGUSER}}
PORT=9000
REDISHOST=${{Redis.REDISHOST}}
REDISPASSWORD=${{Redis.REDISPASSWORD}}
REDISPORT=${{Redis.REDISPORT}}
REDISUSER=${{Redis.REDIS_PRIVATE_URL}}
REDIS_URL=${{Redis.REDIS_PRIVATE_URL}}
CACHE_REDIS_URL=${{Redis.REDIS_PRIVATE_URL}}
STORE_CORS=/vercel.app$/
ADMIN_CORS=/vercel.app$/
MEDUSA_BACKEND_URL=https://stroyberymedusabackend-production.up.railway.app/
DATABASE_URL=${{Postgres.DATABASE_PRIVATE_URL}}
DATABASE_TYPE=postgres
PGHOST=${{Postgres.PGHOST}}
PGPASSWORD=${{Postgres.PGPASSWORD}}
PGPORT=${{Postgres.PGPORT}}
PGUSER=${{Postgres.PGUSER}}
PORT=9000
REDISHOST=${{Redis.REDISHOST}}
REDISPASSWORD=${{Redis.REDISPASSWORD}}
REDISPORT=${{Redis.REDISPORT}}
REDISUSER=${{Redis.REDIS_PRIVATE_URL}}
REDIS_URL=${{Redis.REDIS_PRIVATE_URL}}
CACHE_REDIS_URL=${{Redis.REDIS_PRIVATE_URL}}
STORE_CORS=/vercel.app$/
ADMIN_CORS=/vercel.app$/
MEDUSA_BACKEND_URL=https://stroyberymedusabackend-production.up.railway.app/
DATABASE_URL=${{Postgres.DATABASE_PRIVATE_URL}}
I changed your public database URLs to private URLs My only concern is that you also seem to specify parts of the connection string as well (PGHOST, PGPORT, REDISHOST, etc..) The problem is that railway doesn't show the service variables for private urls connection parts by default if you're using those individual parts to build a connection somewhere in your script then it's possible you'll still be connected over the public network there is of course a way to show the private connection string parts in a database but that would involve using a different service for the database which may take some more work to set up, and I'm personally unsure of how to transfer data between such services (I'm not all that knowledgeable about databases) Do you know if you're using those individual connection parts to connect to the database or do you use the entire connection string (DATABASE_URL and REDIS_URL), if you're only using the entire connection string then the above configuration should work fine
testerOne
testerOneOP8mo ago
The documentation only lists these variables, I think I'll delete everything else
No description
Fragly
Fragly8mo ago
oh fantastic! then the above configuration should work fine
testerOne
testerOneOP8mo ago
i can use just that ?
No description
Fragly
Fragly8mo ago
nope, replace:
DATABASE_URL=${{Postgres.DATABASE_URL}}
REDIS_URL=${{Redis.REDIS_URL}}
DATABASE_URL=${{Postgres.DATABASE_URL}}
REDIS_URL=${{Redis.REDIS_URL}}
with
DATABASE_URL=${{Postgres.DATABASE_PRIVATE_URL}}
REDIS_URL=${{Redis.REDIS_PRIVATE_URL}}
DATABASE_URL=${{Postgres.DATABASE_PRIVATE_URL}}
REDIS_URL=${{Redis.REDIS_PRIVATE_URL}}
testerOne
testerOneOP8mo ago
Ok Is this the reason why I had 40 GB?@Fragly
testerOne
testerOneOP8mo ago
Should I still have settings here? It's a pity that you don't have remote access.
No description
No description
Fragly
Fragly8mo ago
yes don't change anything in the database services very likely
testerOne
testerOneOP8mo ago
I also have a long delay when I request data from the server I can tunnel through the cli, or do a trace, ping, to understand whether this is a problem in my code or in the remoteness of the server?
No description
Fragly
Fragly8mo ago
I can tunnel through the cli
Railway doesn't support SSH or anything like that if that's what you're asking trace route or ping could probably help you debug though I'm in South Africa with a website hosted in US-West on Railway and I have about 400ms response time so unless you're further away from US-West than I am it's likely an issue with your code
testerOne
testerOneOP8mo ago
I am in Kazakhstan. Thank you very much ! I'm going home from work. I set a hard limit of $10 just in case to avoid getting a heart attack in the morning 😄 I will try to work on the site
Fragly
Fragly8mo ago
Sounds good, hope this new configuration works out 🙂
Brody
Brody8mo ago
after reading this thread, I think it would be best if you could show us all your raw variables (the ones that aren't sensitive) for your medusa backend, I'm not quite sure you have followed fragly's instructions perfectly
testerOne
testerOneOP8mo ago
When I have (private) I get this error DATABASE_TYPE=postgres PGHOST=${{Postgres.PGHOST}} PGPASSWORD=${{Postgres.PGPASSWORD}} PGPORT=${{Postgres.PGPORT}} PGUSER=${{Postgres.PGUSER}} PORT=9000 REDISHOST=${{Redis.REDISHOST}} REDISPASSWORD=${{Redis.REDISPASSWORD}} REDISPORT=${{Redis.REDISPORT}} REDISUSER=${{Redis.REDISUSER}} REDIS_URL=${{Redis.REDIS_URL}} CACHE_REDIS_URL=${{Redis.REDIS_URL}} STORE_CORS=/vercel.app$/ ADMIN_CORS=/vercel.app$/ MEDUSA_BACKEND_URL=https://stroyberymedusabackend-production.up.railway.app/ DATABASE_URL=${{Postgres.DATABASE_URL}}
No description
Brody
Brody8mo ago
you didn't do anything fragly has said, please review his messages
testerOne
testerOneOP8mo ago
DATABASE_URL=${{Postgres.DATABASE_PRIVATE_URL}} REDIS_URL=${{Redis.REDIS_PRIVATE_URL}} Here yea ? When I put this I get an error, screenshot of which is aboveI think I can remove all other variables, but I can’t put (private) Because I get an error Both at the back and at the front
No description
No description
No description
Brody
Brody8mo ago
you need to check the deployment logs
testerOne
testerOneOP8mo ago
} [ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND redis.railway.internal at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26) [ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND redis.railway.internal at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26) [ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND redis.railway.internal at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26) Error: getaddrinfo ENOTFOUND redis.railway.internal at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26) { errno: -3007, code: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'redis.railway.internal' }
Brody
Brody8mo ago
update the redis variable to -
REDIS_URL=${{Redis.REDIS_PRIVATE_URL}}?family=6
REDIS_URL=${{Redis.REDIS_PRIVATE_URL}}?family=6
testerOne
testerOneOP8mo ago
I'll try it now thanks
No description
testerOne
testerOneOP8mo ago
Holy! it works ! Thank you very much
Brody
Brody8mo ago
no problem
testerOne
testerOneOP7mo ago
I didn't change anything but my images disappeared.
No description
testerOne
testerOneOP7mo ago
@BrodyCould this be due to the settings we used?
Brody
Brody7mo ago
no, but what kind of app is this again?
testerOne
testerOneOP7mo ago
Get started with Next.js for e-commerce | Medusa
Learn how to get started with a Next.js storefront and Medusa. The Next.js Starter includes ready-integrations with plugins like Stripe and Algolia. It offers features like customer accounts, cart and checkout flows, and more.
Brody
Brody7mo ago
do you have a volume mounted to it?
testerOne
testerOneOP7mo ago
What do you have in mind?
Brody
Brody7mo ago
haha that was a yes or no question
testerOne
testerOneOP7mo ago
I don't know
Brody
Brody7mo ago
please check
testerOne
testerOneOP7mo ago
volume mounted?
Brody
Brody7mo ago
yep thats what i asked, do you have one mounted to the medusa backend?
testerOne
testerOneOP7mo ago
More likely no than yes. This is the first time I've ever heard of this
Brody
Brody7mo ago
please check
testerOne
testerOneOP7mo ago
In any case, I don't even know how to do it
Brody
Brody7mo ago
look at the service on the project canvas, does it have a volume?
testerOne
testerOneOP7mo ago
here?
No description
testerOne
testerOneOP7mo ago
I don't understand what canvas you're talking about
Want results from more Discord servers?
Add your server