#Does React JS Deploy also needs to run in 0.0.0.0 with the env port?

27 messages · Page 1 of 1 (latest)

small ermine
#

Does React JS Deploy also needs to run in 0.0.0.0 with the env variable PORT?

calm orbitBOT
#

Project ID: N/A

small ermine
#

N/A

silent bane
#

what is the specific command in question?

small ermine
#

Sorry, I was a little confused about how to deploy a React Application, so I've set the start command as "npm run build" and the start command(in deploy settings) as "npm run dev", and it went fine, but i've faced the 503 error when I tried to access the application by it's domain. Now(after create this post) i've just saw that the application crashed

silent bane
#

whatever you do, you absolutely do not want to run a dev server on railway

#

and if you can avoid it (you can) you don't need to set any build and start commands in the service settings, so you can go and remove them

#

this looks like a csr rendered react app, so your build command should be building the static files into something like dist, and then your start command should be using serve to serve the static files

small ermine
#

Oh! Thanks, Brody! I fixed it

silent bane
#

care to share what you've learnt with the class?

small ermine
#

Yeah! Sure. I just had to add an script to start the application with with a command-line static HTTP server. In my case, I've just add this script "start": "npx http-server ./dist", to be the start command in deploying settings. Now, i'm just a little confuse about the .htaccess file, because everytime that I reload the page, it reaches 404. I've saw that you don't use .htaccess file in rayway, in this case, you use nginx?

silent bane
#

you'd want to use something suited to serve a react app like serve instead of http-server, like I previously mentioned

#

and there's no use of Apache or nginx on your service because you are doing a react app that uses a node based server

small ermine
#

Oh! Ok. Sorry! Thank you, I think I've got u

silent bane
#

there's also no need to set a start command in the service settings, you can just define them in your package.json

#

your start command should be serve dist -s -p $PORT

#

of course assuming vite builds into dist, your project might be setup differently

small ermine
#

Thank you so much, Brody! It worked perfectly! I just used "start": "npx serve -s ./dist", instead of "start": "serve dist -s -p $PORT" because I was facing that serve by itself was not found

silent bane
#

you're forgetting the port flag

small ermine
#

Well, I didn't set any port and it worked

silent bane
#

prob cuz you have a port set in your service variables

#

either way, you're not running a dev server anymore so you're good

small ermine
#

Thank you ahahha. Today I've learned a lot. I'm a Junior developer and these stuffs involving deployment are still really complex for me

silent bane
#

no worries glad we could get it sorted out

#

but just checking, no more 404 ?

sturdy juniper