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
Percy15mo ago
Project ID: 12e388d8-83af-4dfe-aeef-72a222fb5503
Thiago Lordello
Thiago Lordello15mo ago
12e388d8-83af-4dfe-aeef-72a222fb5503
Adam
Adam15mo ago
Don’t send requests to localhost, send them to 0.0.0.0
Thiago Lordello
Thiago Lordello15mo ago
Okay Adam. I will try. Thanks.
Thiago Lordello
Thiago Lordello15mo ago
Dont success Adam.
Thiago Lordello
Thiago Lordello15mo ago
My problem is not send locally. I dont response when i send url from my deploy on raily.
Brody
Brody15mo ago
why would your backend make an http request, the /login endpoint should just have code that does the login
Thiago Lordello
Thiago Lordello15mo 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
Brody15mo 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 Lordello15mo 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
Brody15mo ago
show me the code that connects to the database?
Thiago Lordello
Thiago Lordello15mo ago
Im using on my appl .env
Brody
Brody15mo ago
what
Thiago Lordello
Thiago Lordello15mo ago
Brody
Brody15mo ago
show me what this logs on railway (please blur the password)
Brody
Brody15mo ago
and just remove the password from that log line going forward
Thiago Lordello
Thiago Lordello15mo ago
One moment
Thiago Lordello
Thiago Lordello15mo ago
Brody
Brody15mo ago
you might have missed it, but i asked for the output of that log on railway, not your local host
Thiago Lordello
Thiago Lordello15mo ago
Sure okay
Brody
Brody15mo ago
do you have this code in a github repo?
Thiago Lordello
Thiago Lordello15mo ago
Yes i have
Thiago Lordello
Thiago Lordello15mo ago
GitHub
GitHub - thiagolordello/todolist_backend
Contribute to thiagolordello/todolist_backend development by creating an account on GitHub.
Brody
Brody15mo ago
https://github.com/thiagolordello/todolist_backend/blob/main/.env delete this asap you should not be using a .env file for that
csd4ni3l
csd4ni3l15mo ago
also this is a public github repo so anyone can view your passwords so thats also not good. Right Brody?
Brody
Brody15mo 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 Lordello15mo ago
Yes i will delete
Brody
Brody15mo ago
and regen the credentials in the database plugins settings
Thiago Lordello
Thiago Lordello15mo ago
file deleted
Brody
Brody15mo 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 Lordello15mo ago
Yes Brody i change password from database
Brody
Brody15mo ago
let me know when that file is deleted
Thiago Lordello
Thiago Lordello15mo ago
Now i delete config.json Sory for expose my credentials
Brody
Brody15mo 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 Lordello15mo ago
yes i will remove and add in git ignore
Brody
Brody15mo ago
show me a screenshot of your service variables please
Thiago Lordello
Thiago Lordello15mo ago
Done Brody
Thiago Lordello
Thiago Lordello15mo ago
Brody
Brody15mo 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 Lordello15mo ago
Okay Brody. Which variables of database will be necessary? The same 5 variables under ?
Brody
Brody15mo 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 Lordello15mo ago
Okay i saw example with uri. / with uri const sequelize = new Sequelize('mysql://localhost:3306/database', {})
Brody
Brody15mo ago
that would be the example
Thiago Lordello
Thiago Lordello15mo ago
Brody Im imagine done. Is necessary ohter change ?
Brody
Brody15mo 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 Lordello15mo ago
Oh sory Brody. this hard code its something test now. I try change for use variable reference Im making changes variables
Brody
Brody15mo ago
please don't hardcode stuff like that, even for testing, it's bad practice
Thiago Lordello
Thiago Lordello15mo ago
Okay i making the correct
Brody
Brody15mo ago
you have 3 different sequelize constructors, please sort that out
Thiago Lordello
Thiago Lordello15mo 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
Brody15mo 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 Lordello15mo ago
Okay Brody. I refactor my code sequelize
Brody
Brody15mo ago
show me a screenshot please
Thiago Lordello
Thiago Lordello15mo ago
Yes i complete code of sequelize.
Brody
Brody15mo ago
^
Thiago Lordello
Thiago Lordello15mo ago
and set in my .env files /config /node_modules .env this is my code now
Brody
Brody15mo 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 Lordello15mo ago
I create for my ambient. Because will not send but okay i delete now
Brody
Brody15mo 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 Lordello15mo ago
I don't put the json config either?
Brody
Brody15mo ago
no config.json. again please stop hard coding credentials
Thiago Lordello
Thiago Lordello15mo ago
okay
Brody
Brody15mo ago
I must admit, I am getting a bit tired of repeating that have you updated your repo?
Thiago Lordello
Thiago Lordello15mo ago
Sorry, I just wanted to confirm. No
Brody
Brody15mo ago
please do so that I can review the changes
Thiago Lordello
Thiago Lordello15mo ago
It's true. But I'm thinking that my code is not ok. sequelize code.
Thiago Lordello
Thiago Lordello15mo ago
Thiago Lordello
Thiago Lordello15mo 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
Brody15mo ago
it is not correct, you again, did not listen to my instructions these instructions specifically
Thiago Lordello
Thiago Lordello15mo ago
Okay i will verify of code
Brody
Brody15mo ago
let me know when you are using MYSQL_URL
Thiago Lordello
Thiago Lordello15mo ago
Brody i change and send my git
Brody
Brody15mo ago
send a screenshot of the service variables please
Thiago Lordello
Thiago Lordello15mo ago
Brody
Brody15mo ago
can i ask, why are you so bad at following directions?
Thiago Lordello
Thiago Lordello15mo ago
The CLI Railway is already installed on my machine
Brody
Brody15mo ago
you need to add a variable reference for MYSQL_URL
Thiago Lordello
Thiago Lordello15mo ago
Okay
Brody
Brody15mo ago
send another screenshot once thats done
Thiago Lordello
Thiago Lordello15mo ago
I had misunderstood
Thiago Lordello
Thiago Lordello15mo ago
Brody
Brody15mo 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 Lordello15mo ago
Okay I wil make changes Brody i put modifications in git
Brody
Brody15mo 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 Lordello15mo ago
I add ignore with text of the link. Then i send of my git. But i dont see node module dir
Brody
Brody15mo ago
Brody
Brody15mo ago
well thats all i can think of right now, test the login endpoint like you did here
Thiago Lordello
Thiago Lordello15mo ago
Okay thanks My app crashed
Brody
Brody15mo ago
logs please
Thiago Lordello
Thiago Lordello15mo ago
Yeah
Brody
Brody15mo ago
send them??
Thiago Lordello
Thiago Lordello15mo ago
Analysing log the error related config.json'. I search in my directory but i found it
Brody
Brody15mo 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 Lordello15mo ago
Its possible create other container ? My idea is make the same deploy in other container
Brody
Brody15mo ago
yeah, but you would have to setup that one variable reference again
Thiago Lordello
Thiago Lordello15mo ago
Do you have other plain ?
Brody
Brody15mo 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 Lordello15mo ago
Okay Brody
Brody
Brody15mo ago
well whats the verdict? still broken?
Thiago Lordello
Thiago Lordello15mo 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
Brody15mo 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 Lordello15mo ago
Okay Brody. Very very thank you. I will open other topic.
Brody
Brody15mo ago
next topic, please carefully read everything I say though
Thiago Lordello
Thiago Lordello15mo ago
Yes Brody. Okay