I have implemented routing using the Routing feature provided in ReasonReact. It looks like this. It works great, until I have it being served by a node.js express server. It will still route, but when I refresh I get for example cannot GET /about
. Seems like the server is trying to serve a directory or file that doesn't exist. I have tried to change the mountpath from "/"
to "*"
, but to no avail.
Anyone have an idea how to get routing working on a ReasonReact app being served by a Node.js Express server?
Here is what my server looks like:
import express from "express";
import path from "path";
const app = express();
const PORT = process.env.PORT || 3000;
//serve static files
app.use(express.static(path.resolve(__dirname, "..", "..", "my-reason-react-app", "public")));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "..", "my-reason-react-app", "public", "index.html"));
});
app.listen(PORT, () => {
console.log(`listening on http://localhost:${PORT}`);
});