0

I'm trying to deploy create-react-app using express.js. I'm also using client side routing (react-router-dom v5) with basename my-app.

When I refresh page the following urls via browser:

but when I refresh page with url https://my-website.com/my-app/:type/:id (for example: https://my-website.com/my-app/polar/12345.)

I'm getting following error:

Uncaught SyntaxError: Unexpected token '<' --> browser tries to load /js/chunk.js and /js/main.chunk.js files requesting these urls:

instead of these:

here is my express server file:

const path = require('path');
const express = require('express');

const app = express();

const root = path.join(__dirname, 'build');

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

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

app.listen(9000, () => {
  console.log('App is running on port 9000');
});

I'm deploying app via docker file into kubernetes cluster on AWS. Pages are served via nginx ingress controller.

Where should be the problem ?

Morty
  • 164
  • 3
  • 18

0 Answers0