Deploying create react app production build to Express JS

In my React project we have set homepage as /chat

“homepage”: “/chat”,

and the project uses create react app scaffolding.

When I do run npm run build

it shows The project was built assuming it is hosted at /chat/.

I want serve production build from express server.

Server.js

const express = require("express");

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

const path = require("path");

const proxy = require("express-http-proxy");

const proxyUrl = process.env.npm_package_proxy;

const port = 8000;

const buildDirName = "build";

const buildDirPath = path.join(__dirname, buildDirName);

app.use(express.static(buildDirPath));

// app.locals.basedir = path.join(__dirname, "/chat");

// app.use(proxy(proxyUrl));

app.locals.basedir = path.join(__dirname, "/chat");

// app.set("basedir", path.join(__dirname, "/chat"));

// app.set("proxy", proxyUrl);

app.get("/*", (req, res) => {

res.sendFile(`${buildDirPath}/index.html`);

});

app.listen(port, () => console.log(`app listening on port ${port}!`));

But with the above code either I get static files served 404 not found or
The script from “http://localhost:8000/chat/static/js/2.1ac70b9e.chunk.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.

The script from “http://localhost:8000/chat/static/js/main.de1f5844.chunk.js” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.

http://localhost:8000/chat

SyntaxError: expected expression, got ‘<’
http://localhost:8000/chat/static/js/2.1ac70b9e.chunk.js

SyntaxError: expected expression, got ‘<’

http://localhost:8000/chat/static/js/main.de1f5844.chunk.js


Can some one please help with this.