-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (35 loc) · 1.01 KB
/
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
//import dependencies
import express from "express";
import dotenv from "dotenv";
import connectDB from "./config/db.js";
import cors from "cors";
//router imports
import trackRoutes from "./routes/tracks.js";
import siteRoutes from "./routes/site.js";
import testRoutes from "./routes/test.js";
import runBot from "./utils/bot.js";
//making instance
const app = express();
dotenv.config();
//middleware
app.use(express.json({ extented: false }));
app.use(cors());
//inserting router
app.use("/api/tracks", trackRoutes);
app.use("/api/test", testRoutes);
app.use("/api/sites", siteRoutes);
if (process.env.NODE_ENV === "production") {
// Set static folder
app.use(express.static("client/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
}
//Server listening to port
const port = process.env.PORT || 3001;
app.listen(port, () => {
console.log(`listening on port ${port}`);
});
//Connect database
connectDB();
setInterval(runBot, 600000);