-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
57 lines (44 loc) · 1.32 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const express = require("express");
const connectDB = require("./config/db");
const path = require("path");
const cors = require("cors");
const swaggerUi = require("swagger-ui-express");
const bodyParser = require("body-parser")
swaggerDocument = require("./swaggerDocs.json");
const app = express();
// app.use(cors());
// PORT AND HOST
const PORT = process.env.PORT || 5000;
const HOST = "http://localhost";
// Connect to DB
connectDB();
// CORS handler
const corsOptions = {
// origin: process.env.ALLOWED_CLIENTS.split(",")
origin: [
"http://localhost:3000/",
"http://localhost:5500/",
"http://127.0.0.1:5500/",
"http://127.0.0.1:3000/",
]
}
app.use(cors());
// body perser
// app.use(express.json());
app.use(bodyParser.json());
// file type MIME
app.use(express.static("public"));
// template engine
app.set("views", path.join(__dirname, "/views"));
app.set("view engine", "ejs");
// Routes
// upload file
app.use("/api/files", require("./routes/files"));
// viewFile
app.use("/files", require("./routes/viewFile"));
// donwloadFile
app.use("/files/download", require("./routes/downloadFile"));
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.listen(PORT, () => {
console.log(`Server Up and Running on ${HOST}:${PORT}`);
})