a year ago
Currently I am setting up an app on railway using mySql and a react front end. Currently I have correctly setup the server so that it connects to the sql server, but the server.js file I have keeps getting an error that the port is being used. I have left the PORT variable empty and then it defaults to 8080 which is still being used. I have tried other PORTS to find one, but to no avail.
How do I find the correct port?
77 Replies
a year ago
https://github.com/ethancs13/dbdbdb
a year ago
Okay there's a few simple things you are doing wrong -
You are trying to run two apps (client and server) inside of one Railway service.
Your client is running a development server.
You are attempting to use nodemon in production.
So let's work through the steps one at a time for simplicity sake.
First off, copy the nixpacks.toml and Caddyfile from this repo into your client folder - https://github.com/brody192/create-react-app-starter
a year ago
I see, done!
a year ago
Should be there
a year ago
That is what it defaulted to when I downloaded the file
a year ago
I will fix that
a year ago
Okay, I pushed the change
a year ago
Is this the canvas?
Attachments
a year ago
Yes it is, but for future reference, please do not crop the screenshots.
This will be the client service, open it's settings and set the root directory to /client
a year ago
like this?
Attachments
a year ago
The app is deployed! Thank you so much for your help
a year ago
Okay, but that part works! Thank you
a year ago
Go ahead and deploy MySQL into the same project, and then attach a screenshot of the canvas.
a year ago
what do you mean by that exactly sorry
a year ago
Your server needs MySQL doesn't it? therefore you need to deploy MySQL into the project.
a year ago
The mysql server I have is hosted on an aws rds. I have already gotten the app to connect to the db successfully
a year ago
Here is the endpoint mysqlinstance.cx46082i6vq9.us-east-2.rds.amazonaws.com
a year ago
Ah okay, I had no clue you were not going to be using MySQL on Railway.
Go ahead and deploy a new empty service and set the needed service variables, this will be the server service.
a year ago
Okay
a year ago
Then what
Attachments
a year ago
I think the servers are a little slow right now, it has been stuck on applying changes for awhile now.
a year ago
ok that part is done. Now what should i do next
a year ago
I've ran the service but don't understand how to get the front end working now
a year ago
Here is the log as well
Attachments
a year ago
Looks like you have both the frontend and the backend running? what seems to be the issue exactly?
a year ago
This is the page
Attachments
a year ago
Aside from you having the build folder in the client I can't see anything wrong, I even deployed it myself and it works.
So make sure you don't have a build folder in GitHub and make sure it's in your .gitignore
a year ago
oh, okay I gotcha. Thank you
a year ago
Looks like the frontend and backend are working, but there seems to be an issue with the way I setup the CORS headers for railway. What should the client host be?
Attachments
a year ago
Here is the console. The status code is 200 ok
Attachments
a year ago
As shown by those console logs, your frontend is trying to make requests to localhost, it needs to make requests to the backend domain.
a year ago
ok with the port 3000? or just the link
a year ago
I tried to change all my 'localhost:3001' axios requests to the endpoint and I think I broke something
Attachments
a year ago
heres the result. 21.1.0 node version
Attachments
a year ago
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-free": "^6.5.2",
"@mui/material": "^5.15.15",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.6.2",
"bcrypt": "^5.1.1",
"body-parser": "^1.20.2",
"bootstrap": "^5.3.3",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"crypto-browserify": "^3.12.0",
"dayjs": "^1.11.11",
"dotenv": "^16.4.5",
"emotion": "^11.0.0",
"install": "^0.13.0",
"jsonwebtoken": "^9.0.2",
"mysql": "^2.18.1",
"npm": "^10.8.1",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"react": "^18.2.0",
"react-auth-kit": "^3.0.0-alpha.44",
"react-bootstrap": "^2.10.2",
"react-cookie": "^7.1.4",
"react-country-state-city": "^1.1.0",
"react-datepicker": "^7.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.20.1",
"react-scripts": "^5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Here is my package.json. Where would I put that?
a year ago
should I do this in the root package.json?
a year ago
the client one
a year ago
or the client one*
a year ago
Yes of course the client's package.json, that is what we are talking about after all.
a year ago
Okay, done.
a year ago
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
...}
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"engines": {
"node": "21"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
...]
}
}
Like this?
a year ago
looks like there are more babel errors about depreciation.
Attachments
a year ago
seems to work fine
a year ago
still seems fine
a year ago
heres the log
Attachments
a year ago
how do I revert to node 20. I am using the 21
a year ago
I could reproduce the error locally with your project, running this command fixed it -
npm install @babel/plugin-proposal-private-property-in-object --save-dev
a year ago
I will try that. Got node 20 installed
Attachments