forked from louisBrochet/omgServer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
55 lines (45 loc) · 1.94 KB
/
app.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
const express = require("express");
const app = express();
require('dotenv').config();
////////////////// Cors //////////////////////////////
const cors = require('cors')
let corsOptions = {
origin: '*',
credentials: 'true'
}
app.use(cors(corsOptions));
//////////////////////////////////////////////////////
////////////////// Passport //////////////////////////
const passport = require("./config/passport")
app.use(passport.initialize({session: false}));
app.use(passport.session({session: false}));
module.exports = passport;
//////////////////////////////////////////////////////
///////////////// Body-parser ////////////////////////
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({limit: '500mb', extended: true}));
app.use(bodyParser.json({limit: '500mb', extended: true}));
//////////////////////////////////////////////////////
///////////////// SYNC DB ////////////////////////////
const seq = require("./config/config");
seq.sequelize.sync()
.then(() => {
// seq.sequelize.query('ALTER TABLE data DROP CONSTRAINT id');
// seq.sequelize.query('ALTER TABLE data ADD CONSTRAINT pk_user PRIMARY KEY (datetime, userId)');
console.log("--\nDatabase synchronized\n--");
})
.catch((error) => console.log("An error occurred while Synchronization.\n", error));
//////////////////////////////////////////////////////
///////////////// Route modules //////////////////////
const routeUser = require("./routes/routeUser");
const routeTag = require("./routes/routeTag");
const routeData = require("./routes/routeData");
const routeDetectionRanges = require("./routes/routeDetectionRanges");
const routeBolus = require("./routes/routeBolus");
app.use("/api/tags", routeTag);
app.use("/api/users", routeUser);
app.use("/api/data", routeData);
app.use("/api/ranges", routeDetectionRanges);
app.use("/api/bolus", routeBolus);
//////////////////////////////////////////////////////
app.listen(3001, "localhost");