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
Percy2y ago
Project ID: c498f886-3455-4e56-9532-44c33c627d59
root
root2y ago
What are your logs? Also, please do provide your project ID, in case somebody with platform access comes along.
LordMerc
LordMercOP2y ago
c498f886-3455-4e56-9532-44c33c627d59
LordMerc
LordMercOP2y ago
LordMerc
LordMercOP2y ago
LordMerc
LordMercOP2y ago
I'm assuming it built? This is the backend index
LordMerc
LordMercOP2y ago
LordMerc
LordMercOP2y ago
Idk if im doing something wrong or not never tried react before
root
root2y ago
Could you send the deploy logs? (and please actually send the logs, not a screenshot)
LordMerc
LordMercOP2y ago
Doesn't show any deploy logs
root
root2y 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
root2y ago
That's odd.
LordMerc
LordMercOP2y ago
LordMerc
LordMercOP2y ago
Aye, im not sure
root
root2y ago
Oh, it's working fine. Your app is working https://test-react-production.up.railway.app/api
LordMerc
LordMercOP2y ago
hm, just doesnt show the react frontend
LordMerc
LordMercOP2y ago
root
root2y 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
LordMercOP2y ago
um it would be that..
root
root2y 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
LordMercOP2y ago
ah, its all good ill look into next.js tho
root
root2y ago
Start a New React Project – React
The library for web and native user interfaces
root
root2y 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
Brody2y 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
LordMercOP2y 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
root2y 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
Brody2y 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
LordMercOP2y ago
not going to lie, i have absolutely no idea ill be glad to share the repo but yea idk anything about react
Brody
Brody2y ago
share the repo please
Brody
Brody2y ago
you will want to gitignore the build folder
LordMerc
LordMercOP2y ago
gotcha
Brody
Brody2y ago
also you are using react-scripts start big big no no
LordMerc
LordMercOP2y ago
wdym
Brody
Brody2y ago
^
LordMerc
LordMercOP2y ago
oh
Brody
Brody2y ago
i will fix
LordMerc
LordMercOP2y ago
thank ya
Brody
Brody2y 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
LordMercOP2y ago
uhh not that i know of i didn’t rly tinker with anything honestly
Brody
Brody2y ago
have you set a PORT in the service variables?
LordMerc
LordMercOP2y ago
nope
Brody
Brody2y 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
LordMercOP2y ago
gotcha, if ya dont mind what'd ya add to package
Brody
Brody2y ago
serve look at the start command
LordMerc
LordMercOP2y ago
ah what does serve do?
Brody
Brody2y 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
LordMercOP2y ago
ah
Brody
Brody2y ago
all good now?
LordMerc
LordMercOP2y ago
aye preciate your help man!
Brody
Brody2y ago
no problem! glad I could help!
Want results from more Discord servers?
Add your server