R
Railwayā€¢2y ago
Talmax

Need help deploying MERN App. Possibly a monorepo thing

Hello! I am in need of deployment with Railway, when I deploy, it goes to my backend. but I cannot get it to sync to the frontend. like show the frontend instead of the backend. I'm guessing it has to do with the [https://docs.railway.app/deploy/monorepo] (monorepo) thing, but I am still confused. Any help I can use, I will appreciate it.
184 Replies
Percy
Percyā€¢2y ago
Project ID: 2a1d0763-51d3-4df6-bb40-5297cd54f90f
Talmax
TalmaxOPā€¢2y ago
2a1d0763-51d3-4df6-bb40-5297cd54f90f is the project id i think
Brody
Brodyā€¢2y ago
can you share a link to your repo please?
Talmax
TalmaxOPā€¢2y ago
GitHub
GitHub - talmax1124/sweetsbykarla
Contribute to talmax1124/sweetsbykarla development by creating an account on GitHub.
Talmax
TalmaxOPā€¢2y ago
Where should I put this? In which Package.Json?
Brody
Brodyā€¢2y ago
that guide pertains to the frontend so in the package.json in the frontend
Talmax
TalmaxOPā€¢2y ago
My current /frontend start script includes: "start": "PORT=4706 && react-scripts start",
Brody
Brodyā€¢2y ago
I can see
Talmax
TalmaxOPā€¢2y ago
so, should I just add what the guide says to that? or maybe add a new one for just that? like railway-start
Brody
Brodyā€¢2y ago
no, please follow the guide, there's no need to over complicate this
Talmax
TalmaxOPā€¢2y ago
for port I just leave it as is, correct?
Brody
Brodyā€¢2y ago
yes follow the guide please
Talmax
TalmaxOPā€¢2y ago
Ok. Trying railway up now
Brody
Brodyā€¢2y ago
slow your roll you are deploying from github, I don't know why you would use railway up you need to set your root directory to /frontend in the service settings
Talmax
TalmaxOPā€¢2y ago
Well, because I haven't added the repo yet to the service. I like seeing the process instead of going to the actual website and waiting for it to load Ok, still the same thing https://sweetsbykarla-production-ad32.up.railway.app
Brody
Brodyā€¢2y ago
^
Talmax
TalmaxOPā€¢2y ago
I did
Brody
Brodyā€¢2y ago
are you sure?
Talmax
TalmaxOPā€¢2y ago
Talmax
TalmaxOPā€¢2y ago
Sure
Brody
Brodyā€¢2y ago
delete the procfile at the root dir
Talmax
TalmaxOPā€¢2y ago
Brody
Brodyā€¢2y ago
remove the build and start commands you have set
Talmax
TalmaxOPā€¢2y ago
Sweets By Karla
Find the best products for the cheapest prices
Talmax
TalmaxOPā€¢2y ago
blank screen
Brody
Brodyā€¢2y ago
that would be an issue with your code, it does show for a split second
Talmax
TalmaxOPā€¢2y ago
It's my error. Yes it is. my ENV I'm thinking thanks
Brody
Brodyā€¢2y ago
and similarly for your backend, you need to add another blank service to the same project, set the root directory appropriately and then add that repo to it and of course add any service variables you may need
Talmax
TalmaxOPā€¢2y ago
wdym? So, its indeed a monorepo correct?
Brody
Brodyā€¢2y ago
backend folder is missing package.json and the lock file, so you'll want to add those to the backend folder yes it is
Talmax
TalmaxOPā€¢2y ago
but its not using any packages. Sorry, I get confused on stupid stuff. So, do I need all of the packages from the root? Is that what I need and put it there?
Brody
Brodyā€¢2y ago
your backend is most certainly using packages lol
Talmax
TalmaxOPā€¢2y ago
Oh. I guess its why it doesn't make the website appear after the one second
Brody
Brodyā€¢2y ago
I assume the package.json and pack-lock.json that are currently in the root directory are for the backend, just move them to the correct folder (the backend folder) webpack config too you also have an index.html in the root directory???
Talmax
TalmaxOPā€¢2y ago
No, the index.html is not being used for anything in the root
Brody
Brodyā€¢2y ago
if it's not used for anything then you can delete it lol
Talmax
TalmaxOPā€¢2y ago
Yeah.
Brody
Brodyā€¢2y ago
anything you need clarification on?
Talmax
TalmaxOPā€¢2y ago
Talmax
TalmaxOPā€¢2y ago
So, basically, everything here move it to the backend
Brody
Brodyā€¢2y ago
yes, basically though the railway.toml file is empty too, so you can delete that
Talmax
TalmaxOPā€¢2y ago
so this
Talmax
TalmaxOPā€¢2y ago
Brody
Brodyā€¢2y ago
I just released that the .gitignore file is used by both backend and frontend, so keep that in the root yes, move gitignore to root tho
Talmax
TalmaxOPā€¢2y ago
Ok so since now that I moved that to the backend. Do I need to change things in the package.json in both?
Brody
Brodyā€¢2y ago
and you should not be setting any build or starts commands in your service settings, the build and start commands should be defined in your package.json scripts no, you are done with the frontend, it deployed just fine, you just have a small code issue, don't touch frontend folder or it's contents right now
Talmax
TalmaxOPā€¢2y ago
but the scripts in package.json that is now in the backend when I do npm run dev, runs the scripts to run both frontend and backend so how is it going to work I'm just confused. Sorry
Brody
Brodyā€¢2y ago
change the start script to only start the backend
Talmax
TalmaxOPā€¢2y ago
?
Brody
Brodyā€¢2y ago
the backend start script should just be node server.js
Talmax
TalmaxOPā€¢2y ago
Ok. so when I am in development, should I create a package.json in the root?
Brody
Brodyā€¢2y ago
no? just start the two apps yourself lol you really like to over complicate things don't you
Talmax
TalmaxOPā€¢2y ago
I've never done a monorepo thing, so this is all new to me
Brody
Brodyā€¢2y ago
fair enough
Talmax
TalmaxOPā€¢2y ago
like, when railway had the Heroku thing, all I had to do was add the environment variables and thats it and when I use render, its easy too, but the free tier shuts off after 15 minutes. not like railway thats always up I'm about to hop into a plane in like 10 minutes, do you think you can do a pull request to my repo and help me?
Brody
Brodyā€¢2y ago
yeah sure why not what are you sitting in the lobby on your laptop lol that's commitment
Talmax
TalmaxOPā€¢2y ago
Yeah, well when you want to finish a project, you do it anytime you have
Brody
Brodyā€¢2y ago
cool, I'll do the pr a bit later enjoy your flight
Talmax
TalmaxOPā€¢2y ago
Thanks. Could I have your github user so you can just commit without waiting for the request to be pulled. its about a 2hr 30 flight
Brody
Brodyā€¢2y ago
brody192
Talmax
TalmaxOPā€¢2y ago
Do you tutor or something? I can use your help in the future
Brody
Brodyā€¢2y ago
i have never tutored
Talmax
TalmaxOPā€¢2y ago
Oh ok. Because I am working on like an options thing and I still can't finish it. Need some mentoring or rather guidance on creating / developing it Invited you
Brody
Brodyā€¢2y ago
I'll see what I can do, but this is a railway server after all, so it would have to be in DMS, I have also never done react before, so I don't even know how much help I could be
Talmax
TalmaxOPā€¢2y ago
Oh yeah. Forgot. its fine thanks
Brody
Brodyā€¢2y ago
no worries, ttyl
Talmax
TalmaxOPā€¢2y ago
Brody
Brodyā€¢2y ago
yep, on mobile right now, so I won't get to it just yet
Talmax
TalmaxOPā€¢2y ago
ok are you est?
Brody
Brodyā€¢2y ago
indeed
Talmax
TalmaxOPā€¢2y ago
ok same i thought i was going to have more time to txt w/ u just in case of anything
Brody
Brodyā€¢2y ago
aren't you getting on a plane?
Talmax
TalmaxOPā€¢2y ago
yes, but after I arrive Lol
Brody
Brodyā€¢2y ago
lol I'll be here in 2 hours
Talmax
TalmaxOPā€¢2y ago
I just boarded. but it leaves at like 10:25 Ok. šŸ‘šŸ» Thanks, @Brody . Ttyl hopefully
Talmax
TalmaxOPā€¢2y ago
@Brody Just Landed. I'll check it out. thanks! I'm guessing that for railway, I'll do the same thing but instead I'll use /backend correct? And since its two folders, any backend request i'll do it how now in the frontend
Brody
Brodyā€¢2y ago
any request from the frontend will have to be made to to backend domain
Talmax
TalmaxOPā€¢2y ago
and when I'm in local development.
Brody
Brodyā€¢2y ago
make requests to the locally running backend
Talmax
TalmaxOPā€¢2y ago
ok. when I get home, I'll try everything out. and get to you tmw since its late with any questions i have which hopefully if i figure it out will be none. Thanks for your help!
Brody
Brodyā€¢2y ago
word of warning I didn't touch any code, but I did remove a bunch of frontend related dependencies you had in your backends package.json, I may have missed some, I may have removed something I shouldn't have, please go through the backends package.json and double check everything you need for only the backend is listed there
Talmax
TalmaxOPā€¢2y ago
thx. I'll check when I get home. Good Night
Brody
Brodyā€¢2y ago
night man
Talmax
TalmaxOPā€¢2y ago
Hello, @Brody. I got a question, I am deploying the backend, I just put it as a /backend. But I have this, any idea on how I can get it running? Do I even need the /backend?
Brody
Brodyā€¢2y ago
show me a screenshot of your railway project
Talmax
TalmaxOPā€¢2y ago
Brody
Brodyā€¢2y ago
looks fine I think and you have a green check mark on the backend service, what seems to be the problem
Brody
Brodyā€¢2y ago
your backend is trying to serve the frontend, remove that functionality since your frontend is setup with a way to serve itself now but that does actually mean the backend is online!
Talmax
TalmaxOPā€¢2y ago
But I don't think I have a script to serve the frontend from the backend
Brody
Brodyā€¢2y ago
you have some code that is trying to return an html file, remove that functionality
Talmax
TalmaxOPā€¢2y ago
thats gonna be tough. Let me check Still can't find where its serving that HTML File. in my server.js its not serving a HTML File, only if you go to the URL and the port. šŸ˜® Still looking... Ok, so after looking and looking, there is no way to stop serving the HTML in that port. It's something that React does already, @Brody
Talmax
TalmaxOPā€¢2y ago
Talmax
TalmaxOPā€¢2y ago
It's getting the backend from that port. Which is using this piece of code: if (process.env.NODE_ENV === "production") { app.use(express.static(path.join(__dirname, "/frontend/build"))); app.get("*", (req, res) => res.sendFile(path.resolve(__dirname, "frontend", "build", "index.html")) ); } else { app.get("/", (req, res) => { res.send("API is running...."); console.log("API is running...."); }); }
Brody
Brodyā€¢2y ago
remove that code then lol
Talmax
TalmaxOPā€¢2y ago
Still doesn't it to stop serving the HTML. Now it gets https://backend.sweetsbykarla.net {"message":"Not Found - /","stack":null}
Brody
Brodyā€¢2y ago
okay that's good
Talmax
TalmaxOPā€¢2y ago
but how does it help that the frontend can't still catch the backend in prod.
Brody
Brodyā€¢2y ago
do you have any api routes defined? yes you do, you have a bunch of api routes call them like https://<your backend's domain>/<your api route> from your frontend
Talmax
TalmaxOPā€¢2y ago
you mean in my server.js?
Brody
Brodyā€¢2y ago
no from your frontend
Talmax
TalmaxOPā€¢2y ago
Ok. So I tried doing that, but with the ${process.env.Backend_URI}. I keep getting undefined. So I'm going to see if I can do if statements which is prob going to take a while
Brody
Brodyā€¢2y ago
variables would need to be prefixed with something
Talmax
TalmaxOPā€¢2y ago
wdym by that
Talmax
TalmaxOPā€¢2y ago
I already have env set for both FRONTEND_URI=http://localhost:2200 Backend_URI=http://localhost:2350
Brody
Brodyā€¢2y ago
respectfully, if i ask you to read something, it would be in your best interest to read said thing im not just sending you stuff to read for funnsies
Talmax
TalmaxOPā€¢2y ago
I already saw it
Brody
Brodyā€¢2y ago
you saw it, but you have not read the page
Talmax
TalmaxOPā€¢2y ago
something like this in the doc is what I do: if (process.env.NODE_ENV !== 'production') { analytics.disable(); }
Brody
Brodyā€¢2y ago
not reading the documentation is not a good idea read this please https://create-react-app.dev/docs/adding-custom-environment-variables/
Talmax
TalmaxOPā€¢2y ago
REACT_APP_FRONTEND_URI=http://localhost:2200/ REACT_APP_Backend_URI=http://localhost:2350/ I assume is the point you are getting at correct?
Brody
Brodyā€¢2y ago
yes! i cant spoon feed you everthing, thats not how you learn šŸ™‚ haha, youll get this i know you will
Talmax
TalmaxOPā€¢2y ago
Got it in a console.log. Trying now
Brody
Brodyā€¢2y ago
web dev hard
Talmax
TalmaxOPā€¢2y ago
It is. But its something I want to do for my career software dev and almost everyone starts with web dev well, and most people need a site
Brody
Brodyā€¢2y ago
true, web dev good place to start
Talmax
TalmaxOPā€¢2y ago
Brody
Brodyā€¢2y ago
the cropped screenshot does not give me very much info
Talmax
TalmaxOPā€¢2y ago
Talmax
TalmaxOPā€¢2y ago
When calling the API, it gives me that I changed all my API's in the frontend Would you like to hop on a Live Share>
Brody
Brodyā€¢2y ago
what browser is that
Talmax
TalmaxOPā€¢2y ago
Safari
Talmax
TalmaxOPā€¢2y ago
Brody
Brodyā€¢2y ago
safari gives shit error messages you prob need this https://expressjs.com/en/resources/middleware/cors.html
Talmax
TalmaxOPā€¢2y ago
Oh, I tried that package once. Didn't work for me that well
Brody
Brodyā€¢2y ago
well these errors aren't railway specific so you can totally do your own research here!
Brody
Brodyā€¢2y ago
Talmax
TalmaxOPā€¢2y ago
Wdym Railway specific. I'm still on local I haven't deployed the new API Changes to Railway, @Brody .
Brody
Brodyā€¢2y ago
aren't*
Talmax
TalmaxOPā€¢2y ago
?
Brody
Brodyā€¢2y ago
^
Talmax
TalmaxOPā€¢2y ago
Oh, sorry I guess I'm famous at misreading things.
Brody
Brodyā€¢2y ago
very true
Talmax
TalmaxOPā€¢2y ago
I don't know why this is harder than having things already set up like render or heroku does šŸ˜¦ Just a lot more setup.
Brody
Brodyā€¢2y ago
render and heroku do a whole crap ton of hand holding to fix broken code
Talmax
TalmaxOPā€¢2y ago
which is why I guess why they charge a lot Well, with render, its free, the only thing that is bad is the downtime
Brody
Brodyā€¢2y ago
but this is the outcome of developing without giving any thought to how a cloud server will run your app, you get a whole lot of head aches
Talmax
TalmaxOPā€¢2y ago
Well, I built this using a course by Brad. Because I'm still pretty much a React newbie. well not that newbie.
Brody
Brodyā€¢2y ago
railway runs your code as is, and expects you to have done things more of less correctly
Talmax
TalmaxOPā€¢2y ago
Yeah. But its because they have NixPackas NixPacks because before they deprecated the Heroku thing, I set it up easily
Brody
Brodyā€¢2y ago
I wasn't here for that deprecation thankfully
Talmax
TalmaxOPā€¢2y ago
I still have a project on Railway with Heroku Procfile but if I want to do another project, I have to use nixpacks now So, adjusting to this is very different
Brody
Brodyā€¢2y ago
it would have been a bunch of "why doesn't my code work anymore" with the answer being "you have done absolutely nothing correctly and heroku was doing the heavy lifting fixing everything for you"
Talmax
TalmaxOPā€¢2y ago
since I never had to deal with this True First time for everything
Brody
Brodyā€¢2y ago
railway has rudimentary support for Procfiles
Talmax
TalmaxOPā€¢2y ago
I'm just going to do if statements, so that I don't get the Control Access Things since locally it works well without using the ENV
Brody
Brodyā€¢2y ago
incoming hacky code šŸ«¤ tsk tsk tsk
Talmax
TalmaxOPā€¢2y ago
sometimes hacky code works
Brody
Brodyā€¢2y ago
šŸ˜¬
Talmax
TalmaxOPā€¢2y ago
mildpanic just trying to make this thing run and work. Mostly all, no some my code is hacky and outdated. But it works, obviously, I update here and there, but at least I don't have to worry a lot about re-creating and re-learning the new version of React until I don't need to which yes, is a bad bad idea, but whatever
Brody
Brodyā€¢2y ago
time to learn next
Talmax
TalmaxOPā€¢2y ago
nextjs? Most of the things I do, don't really need the dynamic power of a project, like an e-commerce store. So, most of the time, for what my clients need, I use Astro or 11ty.
Brody
Brodyā€¢2y ago
got any astro apps deployed on railway?
Talmax
TalmaxOPā€¢2y ago
I want to do Next, but I haven't even done a project by myself using React, because all the time I've been improving the same project No. I use vercel to deploy Astro Apps I like how they make deployment be easier
Brody
Brodyā€¢2y ago
lmfao so why the hell arent you using vercel for your frontend for this project
Talmax
TalmaxOPā€¢2y ago
Because of the same reason, I couldn't figure the f on how to make it work. I tried there. No luck.
Brody
Brodyā€¢2y ago
damn even vercel couldnt make out what the hell your repo was
Talmax
TalmaxOPā€¢2y ago
The only place I could make it work was Render.
Brody
Brodyā€¢2y ago
render prob has a team of people who make patches for bad user code
Talmax
TalmaxOPā€¢2y ago
You know of Brad Traversy right?
Brody
Brodyā€¢2y ago
no
Talmax
TalmaxOPā€¢2y ago
then nevermind
Brody
Brodyā€¢2y ago
hes prob a nerd
Talmax
TalmaxOPā€¢2y ago
Anyways, this project was from his e-commerce course just over the years I kept adding on it on my own an old one
Brody
Brodyā€¢2y ago
is it even for an irl store
Talmax
TalmaxOPā€¢2y ago
yurr
Brody
Brodyā€¢2y ago
cool
Talmax
TalmaxOPā€¢2y ago
But his course makes the thing unsecure and all that so, I just been making things better, yk. But still the thing that I can't make work, is this. what you've been helping me on and now I have a stripe error, ugh.
Brody
Brodyā€¢2y ago
ive seen a few people who said they followed a course, and their code and repo where pure spaghetti, no offense
Talmax
TalmaxOPā€¢2y ago
Yeah. It's why I keep on trying to improve it.
Brody
Brodyā€¢2y ago
youll prob want to properly configure cors, you currently have a wildcard
Talmax
TalmaxOPā€¢2y ago
But if I was a good dev, I would be able to make one of my own and make it a good one, but until then, I just have to make a spagetti code into a better one
Brody
Brodyā€¢2y ago
fair
Talmax
TalmaxOPā€¢2y ago
Let me do these if statements to at least see if I can get something running. and I'll fix it later in the line
Talmax
TalmaxOPā€¢2y ago
Hey @Brody! Hacky code works. https://sweetsbykarla.net
Sweets By Karla
Find the best products for the cheapest prices
Brody
Brodyā€¢2y ago
yes hello bakery shop, i would like to place an order for one iphone 13
Talmax
TalmaxOPā€¢2y ago
Lmafo. Now, I just got to recheck my routes, and see that everything works
Brody
Brodyā€¢2y ago
awsome, happy you got it working
Talmax
TalmaxOPā€¢2y ago
Sure, would you like the frosty that has 256GB or do you want me to still keep getting your money by keeping it plain? LMAO
Brody
Brodyā€¢2y ago
I'd like to buy the 256gb frosty with cash please
Want results from more Discord servers?
Add your server