I have deployed a MERN stack webiste on render, my frontend loads fine but my backend says its live but when I click the link I get the error Cannot GET /.
So I was able to get the travel data, but I think the way I’m trying to serve my static files is wrong. I have my static files in my mern-frontend repo. mern-frontend/public, how would I access that with express?
Would it be
app.use(express.static(‘mern-frontend/public’)); ?
The repo you’ve shared doesn’t appear to contain any frontend code, so you won’t be able to reference the files across services/repos.
A common MERN setup is a Static Site with the “React” part and a Web Service for the “Express” part. The Express/backend is usually just an API to which the static frontend makes client-side (from the browser) calls. Maybe you don’t need to serve your frontend static files with your backend?
I understand that, but my frontend is still not communicating with my backend.
When I go to the “Travels” tab on my frontend, I should be able to see a travel history displayed
When I go to “add travel” on that same page and try to add a travel, I get an error. This has me assume my backend isn’t communicating with my frontend.
When I deploy my backend with the code added:
app.get(‘/’, function (req, res) {
res.redirect(‘/travels’)
});
my backend link shows me the list of travel histories that should be appearing on my frontend /TravelLogPage.
Would it be more helpful if I linked both of my backend and frontend repos? I am genuinely lost on what to do, I feel like it should be a simple fix but I just am not understanding where the disconnect is happening between my frontend and backend.
Your frontend and backend are separate services on separate domains. So the frontend calling just /travels won’t reach the backend. It would need to call the full URL of the backend https://two90-backend.onrender.com/travels
Or, you could use the Redirects and Rewrites feature of Static Sites to rewrite the static /travels to https://two90-backend.onrender.com/travels