R
Railway16mo ago
LordMerc

Hosting React frontend with Express backend

Need assistance with hosting a very simple site, not sure what I'm missing. Works fine as localhost but live is acting differently.
53 Replies
Percy
Percy16mo ago
Project ID: c498f886-3455-4e56-9532-44c33c627d59
root
root16mo ago
What are your logs? Also, please do provide your project ID, in case somebody with platform access comes along.
LordMerc
LordMerc16mo ago
c498f886-3455-4e56-9532-44c33c627d59
LordMerc
LordMerc16mo ago
LordMerc
LordMerc16mo ago
LordMerc
LordMerc16mo ago
I'm assuming it built? This is the backend index
LordMerc
LordMerc16mo ago
LordMerc
LordMerc16mo ago
Idk if im doing something wrong or not never tried react before
root
root16mo ago
Could you send the deploy logs? (and please actually send the logs, not a screenshot)
LordMerc
LordMerc16mo ago
Doesn't show any deploy logs
root
root16mo ago
Also, for full-stack React I'd recommend Next.js (https://nextjs.org) or Remix (https://remix.run), as those support TypeScript better and are likely to be generally nicer and significantly faster than an Express backend.
Next.js by Vercel - The React Framework for the Web
Used by some of the world's largest companies, Next.js enables you to create full-stack Web applications by extending the latest React features, and integrating powerful Rust-based JavaScript tooling for the fastest builds.
root
root16mo ago
That's odd.
LordMerc
LordMerc16mo ago
LordMerc
LordMerc16mo ago
Aye, im not sure
root
root16mo ago
Oh, it's working fine. Your app is working https://test-react-production.up.railway.app/api
LordMerc
LordMerc16mo ago
hm, just doesnt show the react frontend
LordMerc
LordMerc16mo ago
root
root16mo ago
You need to add a static file server What are you using to build your frontend? And please, for heaven's sake, please don't say create-react-app
LordMerc
LordMerc16mo ago
um it would be that..
root
root16mo ago
Oh dear Uh, I'm afraid I don't know how you would hook that up to a custom file server, sorry If you switched to Vite, I could tell you
LordMerc
LordMerc16mo ago
ah, its all good ill look into next.js tho
root
root16mo ago
Start a New React Project – React
The library for web and native user interfaces
root
root16mo ago
Cool! If you're using Next.js, I'd suggest you check out Vercel for hosting - the edge isn't actually just marketing jargon.
Brody
Brody16mo ago
I share the same sentiment as aleks about create-react-app, it's bad but I do know how to hook it into a static file server so send me a link to your repo and I'll see about modifying your project accordingly
LordMerc
LordMerc16mo ago
Apologies for the late reply, I managed to get it situated and working now but why would react app be bad to work with?
root
root16mo ago
It's deprecated It runs on Webpack, which the creator of Webpack recommends against using There are much better options, like Vite, Rollup, or esbuild
Brody
Brody16mo ago
and because it's default start command starts a dev server that should never be run on railway, so out of curiosity, how did you get it running
LordMerc
LordMerc16mo ago
not going to lie, i have absolutely no idea ill be glad to share the repo but yea idk anything about react
Brody
Brody16mo ago
share the repo please
Brody
Brody16mo ago
you will want to gitignore the build folder
LordMerc
LordMerc16mo ago
gotcha
Brody
Brody16mo ago
also you are using react-scripts start big big no no
LordMerc
LordMerc16mo ago
wdym
Brody
Brody16mo ago
^
LordMerc
LordMerc16mo ago
oh
Brody
Brody16mo ago
i will fix
LordMerc
LordMerc16mo ago
thank ya
Brody
Brody16mo ago
have you set any custom build or start commands in the service settings? https://test-service2.up.railway.app/ only uses 70mb of ram now
LordMerc
LordMerc16mo ago
uhh not that i know of i didn’t rly tinker with anything honestly
Brody
Brody16mo ago
have you set a PORT in the service variables?
LordMerc
LordMerc16mo ago
nope
Brody
Brody16mo ago
only files that where changed are package.json, package-lock.json, and the .gitignore file you'll want to delete the build folder from your repo, and the new . gitignore file will ignore the build folder from now on
LordMerc
LordMerc16mo ago
gotcha, if ya dont mind what'd ya add to package
Brody
Brody16mo ago
serve look at the start command
LordMerc
LordMerc16mo ago
ah what does serve do?
Brody
Brody16mo ago
serve is far more suited to run a web site, the original start command starts a dev server, and you never wanna run a dev server in prod
LordMerc
LordMerc16mo ago
ah
Brody
Brody16mo ago
all good now?
LordMerc
LordMerc16mo ago
aye preciate your help man!
Brody
Brody16mo ago
no problem! glad I could help!