-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathserver.js
34 lines (27 loc) · 816 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
31
32
33
34
const express = require("express");
require("dotenv").config();
const fileRoutes = require("./routes/fileRoutes.js");
const path = require("path");
const app = express();
const port = process.env.PORT || 3000;
app.use(express.static(path.join(__dirname, "public")));
// Routes
app.use("/", fileRoutes);
// Error handling routes
app.use((req, res, next) => {
res.status(404).sendFile(path.join(__dirname, "public", "404.html"));
});
app.use((err, req, res, next) => {
res.status(500).sendFile(path.join(__dirname, "public", "500.html"));
});
// security
app.use((req, res, next) => {
res.setHeader(
"Content-Security-Policy",
"default-src 'self'; script-src 'none'; object-src 'none';"
);
next();
});
app.listen(port, () => {
console.log(`Server running at ${process.env.PUBLIC_URL}`);
});