-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
86 lines (64 loc) · 2.42 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
84
85
86
require('dotenv').config();
const cors = require('cors')
const express = require('express');
const mongoose = require('mongoose');
const fileUpload = require('express-fileupload');
const mongoString = process.env.DATABASE_URL;
mongoose.connect(mongoString);
const database = mongoose.connection;
database.on('error', (error) => {
console.log(error)
})
database.once('connected', () => {
console.log('Database Connected');
})
const usecases = require('./src/routes/usecases');
const usecases_shared = require('./src/routes/usecases_shared');
const endusers = require('./src/routes/endusers');
const adminuser = require('./src/routes/adminuser');
const questionnaire = require('./src/routes/questionnaire');
const users = require('./src/routes/users');
const authJwt = require('./src/middlewares/authJWT');
const interaction = require('./src/routes/interaction');
const analytics = require('./src/routes/analytics');
const trees = require('./src/routes/trees');
const explainers = require('./src/routes/explainers');
const cbr_cycle = require('./src/routes/cbr_cycle');
// Add other service routes here. e.g. questionaires
const app = express();
const PORT = process.env.PORT || 3000;
// enable files upload
app.use(fileUpload({
createParentPath: true
}));
app.use(express.json({limit: '2mb'}));
app.use(cors());
app.use(function (req, res, next) {
res.header(
"Access-Control-Allow-Headers",
"x-access-token, Origin, Content-Type, Accept"
);
next();
});
// For testing purposes
app.get("/", (req, res) => {
res.send("iSee Core API");
});
app.listen(PORT, () => {
console.log(`API is listening on port ${PORT}`);
});
app.use('/api/usecases/', [authJwt.verifyToken, authJwt.isDesignUser], usecases);
// Shared /usecases for design user and end user
app.use('/api/usecases_shared/', [authJwt.verifyToken, authJwt.isDesignUserOrEndUser], usecases_shared);
app.use('/api/enduser/', [authJwt.verifyToken, authJwt.isEndUser], endusers);
app.use('/api/admin/', [authJwt.verifyToken, authJwt.isAdminUser], adminuser);
app.use('/api/cbr/',[authJwt.verifyToken, authJwt.isDesignUser], cbr_cycle)
// Dialog Manager Storage
app.use('/api/interaction/', [authJwt.verifyToken], interaction);
app.use('/api/questionnaire/', questionnaire)
app.use('/api/user/', users)
app.use('/api/analytics/', analytics)
// For Explainer Related
app.use('/api/explainers/', explainers)
// For Explanation Editor
app.use('/api/trees/', trees)