'React application hosted on GCP using Docker only opens when i type the URL folowed by "//" double slash

So basically i have deployed a react application on docker using express to serve my build folders. But the after i deployed the application only opens when i follow the url with "//". I have set the homepage property of package.json to "."

The main js chunk will not load if i just type the application URL . It will load only if the application url is followed by double slash for example https://example.com//

Can any one please make me understand why might this behavior occur? Following is the code for the server.js

const path = require("path");
const express = require("express");
const app = express();
const PORT = process.env.PORT || 3000;

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

app.listen(PORT, () => {
  console.log(`Server started on PORT ${PORT}`);
});

Dockerfile

FROM node:16 AS ui-build
WORKDIR /usr/src/app/
COPY . .
RUN npm install && npm run build 
EXPOSE 3000

ENV PORT 3000
ENTRYPOINT ["node", "server/server.js"]

package.json

  {
      "name": "app",
      "version": "0.1.0",
      "homepage": ".",
      "private": true,
      "dependencies": {...
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source