-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (34 loc) · 1.27 KB
/
index.js
File metadata and controls
44 lines (34 loc) · 1.27 KB
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
var express = require('express');
var path = require('path');
const PORT = process.env.PORT || 3000
var app = express();
app.enable('trust proxy');
app.use(express.json());
app.use('/resources', express.static('public'));
const controllers = {
webproxy: require('./controllers/ctrlWebProxy.js'),
annotations: require('./controllers/ctrlAnnotations.js'),
}
const asyncMiddleware = fn =>
(req, res, next) => {
Promise.resolve(fn(req, res, next))
.catch(next);
};
app.get('/ui', function (req, res) {
res.sendFile(path.join(__dirname + '/html/index_ui.html'));
});
app.get('/annotator', asyncMiddleware(async (req, res, next) => {
if (req.query.requestType == "webproxy") {
await controllers.webproxy.manageRequest(req, res);
} else {
res.send("Select a requestType");
}
}));
app.get('/api/search', controllers.annotations.ctrlSearchAnnotationsGET)
app.get('/api/annotations', controllers.annotations.ctrlAnnotationsGET)
app.get('/api/annotations/:id', controllers.annotations.ctrlAnnotationGET)
app.post('/api/annotations', controllers.annotations.ctrlAnnotationPOST)
app.delete('/api/annotations/:id', controllers.annotations.ctrlAnnotationDELETE)
app.listen(PORT, function () {
console.log('Example app listening on port ' + PORT)
});