-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (27 loc) · 837 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const express = require("express");
const { logUrl } = require("./utils/helper-functions");
const imageRouter = require("./routers/imageRouter");
const commentRouter = require("./routers/commentRouter");
const app = express();
const PORT = 8080;
// MIDDLEWARE
if (process.env.NODE_ENV == "production") {
app.use((req, res, next) => {
if (req.headers["x-forwarded-proto"].startsWith("https")) {
return next();
}
res.redirect(`https://${req.hostname}${req.url}`);
});
}
app.use(logUrl);
app.use(express.static("./public"));
app.use(express.json());
// ROUTES
app.use(imageRouter);
app.use(commentRouter);
app.get("*", (req, res) => {
res.sendFile(`${__dirname}/index.html`);
});
app.listen(process.env.PORT || PORT, () =>
console.log(`Imageboard server listening on port ${PORT}`)
);