Problem in calls url in my fronn end.

I have a problem when i try to send method post on login in my applicatiion. In console the webbrowser when i send method post, i receive a error of axios.post "parent: Error: connect ECONNREFUSED 127.0.2.1:3306". In my database i has sucess in seeds aplicated. Other stranger thing is when i send method post my app make too other send method get. Can i help me ?
35 Replies
Percy
Percyā€¢2y ago
Project ID: a297026f-2372-413d-8aa5-0af4cc4fe8bb
luna
lunaā€¢2y ago
did you mean to use 127.0.0.1 instead?
Thiago Lordello
Thiago LordelloOPā€¢2y ago
a297026f-2372-413d-8aa5-0af4cc4fe8bb Hi Luna. No, my app is sending to 127.0.2.1:3306
luna
lunaā€¢2y ago
1. Why? 2. Are you trying to connect to the local host? 3. Shouldnt you be using env.DATABASE_URL ? šŸ¤”
Thiago Lordello
Thiago LordelloOPā€¢2y ago
On my backend i have this log.
luna
lunaā€¢2y ago
You're connecting to mysql correct? Are you using a hosted db or one via services in railway? If you're using the mysql service I'd highly suggest reading https://docs.railway.app/databases/mysql
Thiago Lordello
Thiago LordelloOPā€¢2y ago
Yes my database stay in here
luna
lunaā€¢2y ago
You likely need to use the envs provided by railway. connecting to localhost isnt going to do anything in this case.
Thiago Lordello
Thiago LordelloOPā€¢2y ago
Okay Luna. Im see this link
Thiago Lordello
Thiago LordelloOPā€¢2y ago
My database there is this varaibles. See
luna
lunaā€¢2y ago
yes... now you need to use that in your code. those are all environment variables that're set
Thiago Lordello
Thiago LordelloOPā€¢2y ago
config .json ?
luna
lunaā€¢2y ago
no.. in your code. instead of hard coding localhost and the port youll need to use the env vars.
Thiago Lordello
Thiago LordelloOPā€¢2y ago
Where local i create variable .env ? In / of the project ? Thanks Luna. Im trying now.
luna
lunaā€¢2y ago
you dont.. your app has access to the env it's in. all the variables above are exposed to it. what language are you using?
Thiago Lordello
Thiago LordelloOPā€¢2y ago
Im using nodejs
luna
lunaā€¢2y ago
you'll need to use process.env. to access them so process.env.MYSQLHOST for example
Thiago Lordello
Thiago LordelloOPā€¢2y ago
I set configurations in my index.js but its no change 127.0.2
Thiago Lordello
Thiago LordelloOPā€¢2y ago
luna
lunaā€¢2y ago
are you actually using those for the mysql connection?
Thiago Lordello
Thiago LordelloOPā€¢2y ago
I'm not sure, but I know that on the railway I have notes for database.
luna
lunaā€¢2y ago
no.. that's a question.. did you change the code to use the envs or are you just logging them? The code you showed above doesn't show you using them.
Thiago Lordello
Thiago LordelloOPā€¢2y ago
This print above is show my actualy code in index. i create too .env in my dir /
Thiago Lordello
Thiago LordelloOPā€¢2y ago
luna
lunaā€¢2y ago
okay.. you dont need a .env
Thiago Lordello
Thiago LordelloOPā€¢2y ago
this is my .env
luna
lunaā€¢2y ago
you just need to use the process.env in your code.
Thiago Lordello
Thiago LordelloOPā€¢2y ago
I commit .env and index.js but is the same problem. Is necessary using in other file. Im using exclusive in index.js
luna
lunaā€¢2y ago
1. DO NOT commit .env files 2. you DO NOT need a .env file 3. use the process.env. in your code to connect instead of hardcoding it. Until you do those steps you're stuck bud. Railway automatically puts all the vars from this in process.env for you just use them.
Thiago Lordello
Thiago LordelloOPā€¢2y ago
Okay i delete my file .env . What should I do now?
luna
lunaā€¢2y ago
like ive said multiple times... when you connect to mysql use the process.env. vars to connect do not hardcode localhost. its not going to work until you do that. I would suggest doing some research on how process.env works in nodejs.
Thiago Lordello
Thiago LordelloOPā€¢2y ago
Okay Luna. I do searches. Thanks for help me.
Brody
Brodyā€¢2y ago
are you having fun?
Thiago Lordello
Thiago LordelloOPā€¢2y ago
Okay Luna. I success. Thank you for help me. Basically i change configs the url. In the past i try send requestions sending url of my backend. Now i change for localhost. This appointment its sucess http://localhost:3001/. After works on my machine, i change requests on my pages frontend and commit. Resolved.
Want results from more Discord servers?
Add your server