Serving static react app over express endpoint returns blank page

Viewed 22

I'm trying to host two react websites in one express server. If I serve one or the other website from the root of the server, endpoint "/", the website displays correctly. If I try to put them in a route like "/route1" should display website1 and "/route2" should display website2. But neither of the websites work, they just display a blank page. However, the tab title and and icon are being displayed correctly. This is the code:

const express = require("express");
const app = express();
const path = require("path");

app.use('/website1', express.static('website1/build'))
app.use(('/website1', req, res, next) => {
    res.sendFile(path.join(__dirname, "website1/build", 'index.html'))
})

app.use('/website2', express.static('website2/build'))
app.use('/website2',(req, res, next) => {
    res.sendFile(path.join(__dirname, "website2/build", 'index.html'))
})
app.listen(1200, (_) => console.log("Server started..."));
0 Answers
Related