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