DEV Community

Discussion on: Deploying a React app with React-Router and an Express Backend

Collapse
 
usamamashkoor profile image
usamamashkoor

I have a followed your approach but i am facing a issue.

I have one home page route at express from which i want to pass through a middle-ware function isResturantOpen when ever the user visits the react app.

app.get('/',passportConfig.isResturantOpen, (req,res) =>{
console.log('reached')
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});

but when i ever i tries to visit my website home of react.js at this url
localhost:5000/ then my above route does not work

but all the routes are being going to this main route.

app.get('*', (req,res) =>{
console.log(req)
// console.log(res)
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});

so now if i want to apply some different express.js middle ware functions on each different routes then how can i do this..?

Can you please help me on this.?