-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (35 loc) · 929 Bytes
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
require('dotenv').config()
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const path = require("path");
const helmet = require("helmet");
const cookieParser = require("cookie-parser");
const PORT = process.env.PORT || 8080;
const app = express();
app.use(helmet());
app.use(cors());
app.use(cookieParser());
app.use(
bodyParser.urlencoded({
extended: true,
})
);
app.use(require("./routes/config"));
const directory = path.join(__dirname, './files');
app.use('/files', express.static(directory));
app.use((req, res, next) => {
const error = new Error("Not found");
error.status = 404;
next(error);
});
// catch all
app.use((error, req, res, next) => {
res.status(error.status || 500);
res.json({
error: error.message,
});
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});