Build successful but Cannot GET / error

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 /.

Link to my backend repo: GitHub - rimshaejaz/290-backend-

My build command is npm install
My star command is node travel-controller.mjs

Hi,

Cannot GET / usually comes from Express when a route/path has issues. In this case, the root path, /.

From the repo you shared, the root path looks for static files in a folder that doesn’t exist: https://github.com/rimshaejaz/290-backend-/blob/main/travel-controller.mjs#L10

Maybe try hitting /travels or the other routes/paths defined in that file.

Alan

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’)); ?

https://two90-backend.onrender.com/travels

here is what the website shows after successfully being deployed.

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?

Alan

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.

backend:

frontend:

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

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.