-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathserver.js
72 lines (59 loc) · 1.49 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const express = require("express");
const cors = require("cors");
const cookieSession = require("cookie-session");
const app = express();
app.use(cors());
/* for Angular Client (withCredentials) */
// app.use(
// cors({
// credentials: true,
// origin: ["http://localhost:8081"],
// })
// );
// parse requests of content-type - application/json
app.use(express.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: true }));
app.use(
cookieSession({
name: "bezkoder-session",
keys: ["COOKIE_SECRET"], // should use as secret environment variable
httpOnly: true,
sameSite: 'strict'
})
);
// database
const db = require("./app/models");
const Role = db.role;
db.sequelize.sync();
// force: true will drop the table if it already exists
// db.sequelize.sync({force: true}).then(() => {
// console.log('Drop and Resync Database with { force: true }');
// initial();
// });
// simple route
app.get("/", (req, res) => {
res.json({ message: "Welcome to bezkoder application." });
});
// routes
require("./app/routes/auth.routes")(app);
require("./app/routes/user.routes")(app);
// set port, listen for requests
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});
function initial() {
Role.create({
id: 1,
name: "user",
});
Role.create({
id: 2,
name: "moderator",
});
Role.create({
id: 3,
name: "admin",
});
}