Fullstack app - after deplyment there are routes that throw a 404 error

I deployed a full stack app, in local it’s working fine but in production there are routes where it throws a 404 error. I mean I can see home page fine and profile of the user, but when I try search bar, cart or create a course, it throws a 404 error.

https://online-store-a5kz.onrender.com/

repo: GitHub - dreyanfranco/online-store

Appreciate the help

Hey,

These are the symptoms of not setting up rewrites correctly for static sites, you’ll need every request coming in to go through your client-side router first, so it can then dispatch the request to the appropriate page/component.

See https://docs.render.com/deploy-create-react-app#using-client-side-routing for more explanation.

If you’re not using a static site but a web service, you need to make sure that the routes you’ve set up are correct and that your client-side router is working properly. The principles of client-side routing remain the same.

Jérémy.
Render Support, UTC+3

Hey,

I’m using a web service. Locally all routes and working as they should

this is the index.js of the server, I dont think I’m missing anything here

const express = require(“express”)
const cookieParser = require(“cookie-parser”)
const cors = require(“cors”)
const path = require(“path”)
require(“dotenv”).config()
require(“./db/mongodb”)
const cloudinary = require(“cloudinary”).v2

cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
})

const app = express()
app.use(cookieParser())
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cors())

app.use(express.static(path.join(__dirname, “…/client/dist”)))

require(“./routes”)(app)
require(“./error-handling”)(app)

app.get(“*”, (req, res) => {
res.sendFile(path.join(__dirname, “…/client/dist/index.html”))
})

const PORT = 5005

app.listen(PORT, () => {
console.log(Server listening on http://localhost:${PORT})
})

module.exports = app

Hey,

Could you provide more specific examples of which routes or what exactly is failing? When I browse your service, most routes seem to be working fine and most things aren’t showing errors. Your service seems generally available and healthy, so the issue is likely due to some configuration errors.

Jérémy.
Render Support, UTC+3

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