-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
85 lines (63 loc) · 2.13 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
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
73
74
75
76
77
78
79
80
81
82
83
const app = require("cellebrite-express")();
const routes = require('./routers');
const bodyParser = require("body-parser");
const before = require("./middleware/before.middleware");
const after = require("./middleware/after.middleware");
const express = require("express");
const contextService = require('request-context');
// const app = express();
app.set('view engine', 'ejs')
console.log('pm2')
app.use(before)
app.use(bodyParser.json())
app.use(after);
app.use((req,res,next)=>{
contextService.set('requestId', req.headers['requestId'] || uuid())
})
const utils = require("util");
// require('./routers').defineRoutes(app);
// app.listen = utils.promisify(app.listen);
// routes();
const v1 = express.Router();
v1.get('/test', (req, res) => {
res.json({ "version": "1" })
})
const v2 = express.Router();
v2.get('/test', (req, res) => {
res.json({ "version": "2" })
})
app.use('/v1',v1);
app.use('/v2',v2);
require('./routers')(app);
const db = require('./db');
(async function () {
try {
await db.initDB()
const port = process.env.PORT || 8080
// await app.listen(port)
// console.log('Server is up: ' + port);
// // await db.models.employee.build({ name: "Dudu", email: "[email protected]" }).save()
// const dudu2 = await db.models.employee.create({ name: "Dudu 2", email: "[email protected]" })
// const dudu3 = await db.models.employee.create({ name: "Dudu 3", email: "[email protected]" })
// const rnd = await db.models.department.create({ name: "R&D" });
// dudu2.departmentId = rnd.id;
// dudu3.departmentId = rnd.id;
// await dudu2.save();
// await dudu3.save();
// const duduWithDept = await db.models.employee.findById(dudu2.id, {
// include: ['department']
// });
// const deptWithDudus = await db.models.department.findAll({
// where: {
// name: "R&D"
// },
// include: ['employees']
// })
// console.log(duduWithDept.department.name)
// console.log('test')
}
catch (err) {
console.error(err);
throw err;
}
})()