Request of backend is failed.

If i start my backend locally and send requestion post for localhost:3001/login my request it works acessing database on railway. But if i send the same requestion for my app deployed request, its failed. My request with problem is https://to-do-list-backend-production-0a07.up.railway.app/login. Can i help me ?
105 Replies
Percy
Percy2y ago
Project ID: 12e388d8-83af-4dfe-aeef-72a222fb5503
Thiago Lordello
Thiago LordelloOP2y ago
12e388d8-83af-4dfe-aeef-72a222fb5503
Adam
Adam2y ago
Don’t send requests to localhost, send them to 0.0.0.0
Thiago Lordello
Thiago LordelloOP2y ago
Okay Adam. I will try. Thanks.
Thiago Lordello
Thiago LordelloOP2y ago
Dont success Adam.
Thiago Lordello
Thiago LordelloOP2y ago
My problem is not send locally. I dont response when i send url from my deploy on raily.
Brody
Brody2y ago
why would your backend make an http request, the /login endpoint should just have code that does the login
Thiago Lordello
Thiago LordelloOP2y ago
Hello Brody. Im trying a test sending im computer (app insomnia) to url puclic of my deploy. In this test i try to use aplication deployed backend. When i start the same application in my machine changing url for localhost:3001/login i sucsess.
Brody
Brody2y ago
this error signifies that your service is making an internal request to 127.0.0.1 (and failing) why is your service trying to make this internal request?
Thiago Lordello
Thiago LordelloOP2y ago
I dont know. I searching this ip but do not show. Could it be that this ip was in the previous settings and so the deploy applied and now I can no longer change? Should I not redeploy the backend?
Brody
Brody2y ago
show me the code that connects to the database?
Thiago Lordello
Thiago LordelloOP2y ago
Im using on my appl .env
Brody
Brody2y ago
what
Thiago Lordello
Thiago LordelloOP2y ago
Brody
Brody2y ago
show me what this logs on railway (please blur the password)
Brody
Brody2y ago
and just remove the password from that log line going forward
Thiago Lordello
Thiago LordelloOP2y ago
One moment
Thiago Lordello
Thiago LordelloOP2y ago
Brody
Brody2y ago
you might have missed it, but i asked for the output of that log on railway, not your local host
Thiago Lordello
Thiago LordelloOP2y ago
Sure okay
Brody
Brody2y ago
do you have this code in a github repo?
Thiago Lordello
Thiago LordelloOP2y ago
Yes i have
Thiago Lordello
Thiago LordelloOP2y ago
GitHub
GitHub - thiagolordello/todolist_backend
Contribute to thiagolordello/todolist_backend development by creating an account on GitHub.
Brody
Brody2y ago
https://github.com/thiagolordello/todolist_backend/blob/main/.env delete this asap you should not be using a .env file for that
csd4ni3l
csd4ni3l2y ago
also this is a public github repo so anyone can view your passwords so thats also not good. Right Brody?
Brody
Brody2y ago
once thats deleted, go into the the database plugin and regen your credentials even if it was a private repo, storing credentials of public facing services in plain text is never a good idea
Thiago Lordello
Thiago LordelloOP2y ago
Yes i will delete
Brody
Brody2y ago
and regen the credentials in the database plugins settings
Thiago Lordello
Thiago LordelloOP2y ago
file deleted
Brody
Brody2y ago
let me know when you have done these two things have you regened? delete this file too https://github.com/thiagolordello/todolist_backend/blob/main/config/config.json please please stop hardcoding credentials, i cant stress that enough
Thiago Lordello
Thiago LordelloOP2y ago
Yes Brody i change password from database
Brody
Brody2y ago
let me know when that file is deleted
Thiago Lordello
Thiago LordelloOP2y ago
Now i delete config.json Sory for expose my credentials
Brody
Brody2y ago
i also see that you have a node_modules folder, you should not be commiting this to github, remove that folder from github and then add the contents of this link https://www.toptal.com/developers/gitignore/api/node to a .gitignore file at the root of your project and again, let me know when thats done
Thiago Lordello
Thiago LordelloOP2y ago
yes i will remove and add in git ignore
Brody
Brody2y ago
show me a screenshot of your service variables please
Thiago Lordello
Thiago LordelloOP2y ago
Done Brody
Thiago Lordello
Thiago LordelloOP2y ago
Brody
Brody2y ago
now you will need to update your sequelize constructor to use those environment variables, reference the constructer in the docs here https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#instance-constructor-constructor to access (for example) the MYSQLDATABASE variable in code you would use process.env.MYSQLDATABASE i noticed, you have not added the .gitignore file that i provided you with, please do that before anything else
Thiago Lordello
Thiago LordelloOP2y ago
Okay Brody. Which variables of database will be necessary? The same 5 variables under ?
Brody
Brody2y ago
for the most simplistic way, you could actually just use MYSQL_URL but you would need to add that variable reference, as its not listed in your service variables, once thats done you can scroll down on that docs page, and there is an example for uri, of course you will want to use that environment variable instead of hardcoding the value
Thiago Lordello
Thiago LordelloOP2y ago
Okay i saw example with uri. / with uri const sequelize = new Sequelize('mysql://localhost:3306/database', {})
Brody
Brody2y ago
that would be the example
Thiago Lordello
Thiago LordelloOP2y ago
Brody Im imagine done. Is necessary ohter change ?
Brody
Brody2y ago
you did exactly what I said not to do, going forward it might be beneficial for you to read over what I say a few times before you act on it you hardcoded a credential, I have previously said you should never do this, and I told you to use environment variables I even gave you an example on how to use environment variables so please go back and re-read over what I have said
Thiago Lordello
Thiago LordelloOP2y ago
Oh sory Brody. this hard code its something test now. I try change for use variable reference Im making changes variables
Brody
Brody2y ago
please don't hardcode stuff like that, even for testing, it's bad practice
Thiago Lordello
Thiago LordelloOP2y ago
Okay i making the correct
Brody
Brody2y ago
you have 3 different sequelize constructors, please sort that out
Thiago Lordello
Thiago LordelloOP2y ago
Okay thanks Are you talking about the part of the if logic where I check if I use the .env variable? I ajust my code removing hard code
Brody
Brody2y ago
yes, you have 3 different constructors, you should boil that down to just 1 get back to me when this has been completed please
Thiago Lordello
Thiago LordelloOP2y ago
Okay Brody. I refactor my code sequelize
Brody
Brody2y ago
show me a screenshot please
Thiago Lordello
Thiago LordelloOP2y ago
Yes i complete code of sequelize.
Brody
Brody2y ago
^
Thiago Lordello
Thiago LordelloOP2y ago
and set in my .env files /config /node_modules .env this is my code now
Brody
Brody2y ago
once again, you should not be using a .env file for this I don't know how many times I have told you that at this point
Thiago Lordello
Thiago LordelloOP2y ago
I create for my ambient. Because will not send but okay i delete now
Brody
Brody2y ago
you should be using the railway cli locally with railway run npm run debug with this command you will not need a local .env file but let's focus on running the code on railway for now, so have you updated your github repo?
Thiago Lordello
Thiago LordelloOP2y ago
I don't put the json config either?
Brody
Brody2y ago
no config.json. again please stop hard coding credentials
Thiago Lordello
Thiago LordelloOP2y ago
okay
Brody
Brody2y ago
I must admit, I am getting a bit tired of repeating that have you updated your repo?
Thiago Lordello
Thiago LordelloOP2y ago
Sorry, I just wanted to confirm. No
Brody
Brody2y ago
please do so that I can review the changes
Thiago Lordello
Thiago LordelloOP2y ago
It's true. But I'm thinking that my code is not ok. sequelize code.
Thiago Lordello
Thiago LordelloOP2y ago
Thiago Lordello
Thiago LordelloOP2y ago
Because is using process.env I'll see a template ready. Sorry for today Brody My code of sequelize is actualized in github
Brody
Brody2y ago
it is not correct, you again, did not listen to my instructions these instructions specifically
Thiago Lordello
Thiago LordelloOP2y ago
Okay i will verify of code
Brody
Brody2y ago
let me know when you are using MYSQL_URL
Thiago Lordello
Thiago LordelloOP2y ago
Brody i change and send my git
Brody
Brody2y ago
send a screenshot of the service variables please
Thiago Lordello
Thiago LordelloOP2y ago
Brody
Brody2y ago
can i ask, why are you so bad at following directions?
Thiago Lordello
Thiago LordelloOP2y ago
The CLI Railway is already installed on my machine
Brody
Brody2y ago
you need to add a variable reference for MYSQL_URL
Thiago Lordello
Thiago LordelloOP2y ago
Okay
Brody
Brody2y ago
send another screenshot once thats done
Thiago Lordello
Thiago LordelloOP2y ago
I had misunderstood
Thiago Lordello
Thiago LordelloOP2y ago
Brody
Brody2y ago
https://github.com/thiagolordello/todolist_backend/blob/main/models/index.js#L7 this line will fail, there is no config.json anymore
Thiago Lordello
Thiago LordelloOP2y ago
Okay I wil make changes Brody i put modifications in git
Brody
Brody2y ago
okay that index.js file looks good to me you dont have a .gitignore file yet, please use the one i sent you
Thiago Lordello
Thiago LordelloOP2y ago
I add ignore with text of the link. Then i send of my git. But i dont see node module dir
Brody
Brody2y ago
well thats all i can think of right now, test the login endpoint like you did here
Thiago Lordello
Thiago LordelloOP2y ago
Okay thanks My app crashed
Brody
Brody2y ago
logs please
Thiago Lordello
Thiago LordelloOP2y ago
Yeah
Brody
Brody2y ago
send them??
Thiago Lordello
Thiago LordelloOP2y ago
Analysing log the error related config.json'. I search in my directory but i found it
Brody
Brody2y ago
that looks to be an error from an old codebase, it complains about not finding a config.json thats being imported by /models/index.js, but you have removed that import like i said, and the code on github no longer imports a config,json
Thiago Lordello
Thiago LordelloOP2y ago
Its possible create other container ? My idea is make the same deploy in other container
Brody
Brody2y ago
yeah, but you would have to setup that one variable reference again
Thiago Lordello
Thiago LordelloOP2y ago
Do you have other plain ?
Brody
Brody2y ago
so make a new blank service (inside of the same project) setup that MYSQL_URL variable reference, then add your github repo in the service settings then after that, you can delete the old service that crashed
Thiago Lordello
Thiago LordelloOP2y ago
Okay Brody
Brody
Brody2y ago
well whats the verdict? still broken?
Thiago Lordello
Thiago LordelloOP2y ago
Hello Brody. I forget feedback. I delete one line in any file for force deploy. Its necessary for rebuild and backend it works. My new problem now its in front end. This topic can be closed. Thanks for help me Brody.
Brody
Brody2y ago
awsome glad to hear the backend issues have been solved, go ahead and open a new thread for the frontend issues and i will try to help you with that too
Thiago Lordello
Thiago LordelloOP2y ago
Okay Brody. Very very thank you. I will open other topic.
Brody
Brody2y ago
next topic, please carefully read everything I say though
Thiago Lordello
Thiago LordelloOP2y ago
Yes Brody. Okay
Want results from more Discord servers?
Add your server