This repository has been archived by the owner on Jul 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
server.js
117 lines (91 loc) · 2.96 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
require('dotenv').config();
const fs = require('fs');
const path = require('path');
const bodyParser = require('body-parser');
const express = require('express');
const session = require('express-session');
const config = require('./config');
const appPort = config.get('app.port');
const sessionOpts = {
secret: config.get('session.secret'),
resave: false,
saveUninitialized: true
};
/**
* Express server scaffolding
*/
const app = express();
app.disable('x-powered-by');
app.use(bodyParser.json());
app.use(bodyParser.text());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(session(sessionOpts));
/**
* Main application route
* Gets the html output to the page
*/
app.get('/', (req, res) => {
const filePath = path.join(__dirname, '/public/GeckoApp.html');
fs.readFile(filePath, (err, contents) => {
if (err) {
return res.send('Something went wrong when reading the main html file');
}
res.writeHead(200, {
'Content-Type': 'text/html',
'Content-Length': contents.length
});
return res.end(contents.toString());
});
});
/**
* Serve static files from 'public' directory
*/
app.use(express.static('public'));
/**
* AUTH | Zotero
*/
app.get('/services/zotero/auth/login', require('./routes/services/zotero/auth/login'));
app.get('/services/zotero/auth/verify', require('./routes/services/zotero/auth/verify'));
app.get('/services/zotero/getCollections', require('./routes/services/zotero/getCollections'));
app.get('/services/zotero/getItemsInCollection', require('./routes/services/zotero/getItemsInCollection'));
app.post('/services/zotero/addItems', require('./routes/services/zotero/addItems'));
app.get('/services/paper/getByDOI', require('./routes/services/paper/getByDOI'));
app.get('/services/paper/getEdges', require('./routes/services/paper/getEdges'));
/**
* USER | Session info getters
*/
app.get('/services/user/getAuthInfo', require('./routes/services/user/getAuthInfo'));
/**
* API | Get citedBy from DynamoDB
*/
app.get('/api/v1/getCitedBy', require('./routes/api/v1/getCitingArticles'));
/**
* API | Test endpoint for OA DOI
*/
app.get('/api/v1/query/oadoi', require('./routes/api/v1/query/oadoi'));
/**
* API | Test endpoint for CrossRef queries
*/
app.get('/api/v1/query/crossref', require('./routes/api/v1/query/crossref'));
/**
* API | Test endpoint for COCI queries
*/
app.get('/api/v1/query/coci', require('./routes/api/v1/query/coci'));
/**
* API | Proxy to Microsoft Academic Graph
*/
//app.post('/api/v1/query/microsoft/search', require('./routes/api/v1/query/microsoft/search'));
/**
* API | Proxy to OpenCitations sparql
*/
// app.post('/api/v1/query/occ/sparql', require('./routes/api/v1/query/occ/sparql'));
/**
* API | Mocked response for the client-side refactor
*/
app.get('/api/v1/getMockResponse', require('./routes/api/v1/getMockResponse'));
/**
* Start Express server
*/
app.listen(appPort, () => {
console.log('CitationGecko server listening on port', appPort);
});