-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
37 lines (30 loc) · 1.02 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
const express = require("express");
const path = require("path");
const app = express();
const connectDB = require("./config/db");
const PORT = process.env.PORT || 3000;
const cors = require("cors");
connectDB();
// CORS Setup - Middleware
const corsOptions = process.env.ALLOWED_HOSTS.split(",");
app.use(cors(corsOptions));
// Serve static files - Middleware
app.use(express.static("public"));
app.use(express.static("build"));
// Use JSON by default in POST - Middleware
app.use(express.json());
// Templates
app.set("views", path.join(__dirname, "/views"));
app.set("view engine", "ejs");
// React app
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "build", "index.html"));
});
// Routes
app.use("/api/files", require("./routes/files"));
app.use("/api/files/download", require("./routes/download-file"));
app.use("/files", require("./routes/show"));
app.use("/api/delete", require("./routes/script"));
app.listen(PORT, () => {
console.log(`Listening on PORT ${PORT}`);
});