-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
55 lines (43 loc) · 1.54 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
require('dotenv').config();
const express = require('express');
const cors = require('cors')
const cookieParser = require("cookie-parser");
const { authenticateJWT } = require('./app/middleware/auth.middleware');
const db = require("./app/models");
const initialSampleData = require('./sampleData');
const app = express();
app.use(express.json());
app.use(cors({}))
app.use(cookieParser()); // for parsing cookies
// ---------------------- DATABASE
db.sequelize.sync({
// force: true
// alter: true // alter: true will update the table schema
})
.then(() => {
console.log("Synced db.");
// initialSampleData();
})
.catch((err) => {
console.log("Failed to sync db: " + err.message);
});
// ---------------------- ROUTES ------------
// simple route
app.get("/", (req, res) => {
res.json({ message: "Welcome to SaigonX Back-end." });
});
const authRouter = require("./app/routes/auth.route"); // /api/auth
app.use("/api/auth", authRouter);
const userRouter = require("./app/routes/user"); // /api/user
app.use('/api/user', authenticateJWT, userRouter);
const mapRouter = require("./app/routes/map.route"); // /api/map
app.use("/api/map", mapRouter);
const landRouter = require("./app/routes/land.route"); // /api/land
app.use("/api/land", landRouter);
const leaderboardRouter = require("./app/routes/leaderboard.route"); // /api/leaderboard
app.use("/api/leaderboard", leaderboardRouter);
// set port, listen for requests
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});