An application built in React using react router runs correctly on local machine, but when uploaded to heroku server it only runs correctly for domain.com/ and domain.com/path1/. For my project it is essential that domain.com/path1/path2 also works.
const express = require("express");
const path = require("path");
const app = express();
const port = process.env.PORT || 3000;
app.use(express.json());
// Your static pre-build assets folder
app.use(express.static(path.join(__dirname, "..", "build")));
// Root Redirects to the pre-build assets
app.get("/", function (req, res) {
res.sendFile(path.join(__dirname, "..", "build"));
});
// Any Page Redirects to the pre-build assets folder index.html that // will load the react app
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "..", "build/index.html"));
});
app.listen(port, () => {
console.log("Server is running on port: ", port);
});
this is my server.js file.
I tried everything I could, and now I'm lost.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/kKRYGa3
Comments
Post a Comment