This repository has been archived by the owner on Apr 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
74 lines (59 loc) · 1.95 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
/**
* Peritext server garlic flavoured
* =============
* entrypoint of the node-js application.
* The app interfaces specific routes with the services provided by the app.
* Routes are defined at the end of the file
* @module peritext-server-garlic-flavoured
*/
const https = require('https');
const bodyParser = require('body-parser');
const cors = require('cors');
const express = require('express');
/**
* Internal dependencies
*/
// route handlers (see below)
const citationLocales = require('./routeHandlers/citation-locales');
const citationStyles = require('./routeHandlers/citation-styles');
const renderStory = require('./routeHandlers/render-story');
let config;
// in production mode config variables must be set as environment variables
if (process.env.NODE_ENV === 'production') {
config = {
port: process.env.PORT || 3000,
};
}
// in development mode config variables are retrieved from a json file
// else {
// config = require('./config');
// }
config = {
port: process.env.PORT || 3001,
};
const app = express();
app.use(cors());
// parse application/json
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.use('/temp', express.static(__dirname + '/temp'));
module.exports = app;
/**
* Routes binding
* ==========
* Each express request is handled by a specific route handlers
* Routes definitions and routes handlers are separated
* to facilitate further changes in the server's api
*/
// endpoints related to rendering jobs
app.post('/render-story', cors(), renderStory.createRenderingJob);
app.get('/render-story', cors(), renderStory.getRenderingJob);
// expose citation related data (e.g. "APA style", "english locale")
app.get('/citation-locales/:id?', citationLocales);
app.get('/citation-styles/:id?', citationStyles);
/**
* listening to requests (defaults to 3000)
*/
app.listen(config.port, function(){
console.log('app listening on %s', config.port);
});