-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
69 lines (56 loc) · 1.73 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
const express = require("express");
const bodyParser = require("body-parser");
var path = require('path');
const cors = require("cors");
const {
SERVER_PORT,
ROLES,
CORS_ORIGIN,
SUPERADMIN_USER,
SUPERADMIN_EMAIL,
SUPERADMIN_PASSWORD } = require('./config.js')
const app = express();
var corsOptions = {
origin: CORS_ORIGIN
};
app.use(cors(corsOptions));
// parse requests of content-type - application/json
app.use(bodyParser.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
// set static folder
app.use(express.static(path.join(__dirname, 'public')));
// database
const db = require("./app/models");
const Role = db.role;
db.sequelize.sync({alter: true});
// db.sequelize.sync({force: true}).then(() => { // force: true will drop the table if it already exists
// console.log('Drop and Resync Database with { force: true }');
// initial_role();
// const { initSuperAdmin } = require("./app/controllers/auth.controller");
// initSuperAdmin(SUPERADMIN_USER,
// SUPERADMIN_EMAIL,
// SUPERADMIN_PASSWORD);
// });
// simple route
// app.get("/", (req, res) => {
// res.json({ message: "Welcome." });
// });
// routes
require('./app/routes/auth.routes')(app);
require('./app/routes/user.routes')(app);
require('./app/routes/token.routes')(app);
require('./app/routes/company.routes')(app);
// set port, listen for requests
app.listen(SERVER_PORT, () => {
console.log(`Server is running on port ${SERVER_PORT}.`);
});
function initial_role() {
// initialize type of role user (Role in website world, not in company each user world)
for(let i = 0; i < ROLES.length; i++){
Role.create({
id: i + 1,
name: ROLES[i]
});
}
}