Skip to content

Commit

Permalink
Add catch-all route for serving index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
khadeshyam committed Jan 24, 2024
1 parent 9329eda commit f7b7214
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const postRoute = require("./routes/posts");
const categoryRoute = require("./routes/categories");
const multer = require("multer");
const path = require("path");
const __dirname = process.cwd();

dotenv.config();
app.use(express.json());
Expand Down Expand Up @@ -38,6 +39,10 @@ app.use("/api/users", userRoute);
app.use("/api/posts", postRoute);
app.use("/api/categories", categoryRoute);

app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});

app.listen("5000", () => {
console.log("Backend is running.");
});

0 comments on commit f7b7214

Please sign in to comment.