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
12e388d8-83af-4dfe-aeef-72a222fb5503
Adam
Adam2y ago
Don’t send requests to localhost, send them to 0.0.0.0
Thiago Lordello
Okay Adam. I will try. Thanks.
Thiago Lordello
Dont success Adam.
Thiago Lordello
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
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
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
Im using on my appl .env
Brody
Brody2y ago
what
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
One moment
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
Sure okay
Brody
Brody2y ago
do you have this code in a github repo?
Thiago Lordello
Yes i have
Thiago Lordello
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
Yes i will delete
Brody
Brody2y ago
and regen the credentials in the database plugins settings
Thiago Lordello
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
Yes Brody i change password from database
Brody
Brody2y ago
let me know when that file is deleted
Thiago Lordello
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
yes i will remove and add in git ignore
Brody
Brody2y ago
show me a screenshot of your service variables please
Thiago Lordello
Done Brody
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
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
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
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
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
Okay i making the correct
Brody
Brody2y ago
you have 3 different sequelize constructors, please sort that out
Thiago Lordello
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
Okay Brody. I refactor my code sequelize
Brody
Brody2y ago
show me a screenshot please
Thiago Lordello
Yes i complete code of sequelize.
Brody
Brody2y ago
^
Thiago Lordello
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
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
I don't put the json config either?
Brody
Brody2y ago
no config.json. again please stop hard coding credentials
Thiago Lordello
okay
Brody
Brody2y ago
I must admit, I am getting a bit tired of repeating that have you updated your repo?
Thiago Lordello
Sorry, I just wanted to confirm. No
Brody
Brody2y ago
please do so that I can review the changes
Thiago Lordello
It's true. But I'm thinking that my code is not ok. sequelize code.
Thiago Lordello
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
Okay i will verify of code
Brody
Brody2y ago
let me know when you are using MYSQL_URL
Thiago Lordello
Brody i change and send my git
Brody
Brody2y ago
send a screenshot of the service variables please
Brody
Brody2y ago
can i ask, why are you so bad at following directions?
Thiago Lordello
The CLI Railway is already installed on my machine
Brody
Brody2y ago
you need to add a variable reference for MYSQL_URL
Thiago Lordello
Okay
Brody
Brody2y ago
send another screenshot once thats done
Thiago Lordello
I had misunderstood
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
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
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
Okay thanks My app crashed
Brody
Brody2y ago
logs please
Thiago Lordello
Yeah
Brody
Brody2y ago
send them??
Thiago Lordello
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
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
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
Okay Brody
Brody
Brody2y ago
well whats the verdict? still broken?
Thiago Lordello
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
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
Yes Brody. Okay
Want results from more Discord servers?
Add your server