forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
64 lines (49 loc) · 1.88 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
56
57
58
59
60
61
62
63
'use strict';
var express = require('express');
var compression = require('compression');
var bodyParser = require('body-parser');
function create (env, ctx) {
///////////////////////////////////////////////////
// api and json object variables
///////////////////////////////////////////////////
var api = require('./lib/api/')(env, ctx);
var app = express();
var appInfo = env.name + ' ' + env.version;
app.set('title', appInfo);
app.enable('trust proxy'); // Allows req.secure test on heroku https connections.
if (ctx.bootErrors && ctx.bootErrors.length > 0) {
app.get('*', require('./lib/booterror')(ctx));
return app;
}
app.use(compression({filter: function shouldCompress(req, res) {
//TODO: return false here if we find a condition where we don't want to compress
// fallback to standard filter function
return compression.filter(req, res);
}}));
// app.use(bodyParser({limit: 1048576 * 50, extended: true }));
//if (env.api_secret) {
// console.log("API_SECRET", env.api_secret);
//}
app.use('/api/v1', bodyParser({limit: 1048576 * 50 }), api);
// pebble data
app.get('/pebble', ctx.pebble);
// expose swagger.yaml
app.get('/swagger.yaml', function (req, res) {
res.sendFile(__dirname + '/swagger.yaml');
});
//app.get('/package.json', software);
// define static server
//TODO: JC - changed cache to 1 hour from 30d ays to bypass cache hell until we have a real solution
var staticFiles = express.static(env.static_files, {maxAge: 60 * 60 * 1000});
// serve the static content
app.use(staticFiles);
var bundle = require('./bundle')();
app.use(bundle);
// Handle errors with express's errorhandler, to display more readable error messages.
var errorhandler = require('errorhandler');
//if (process.env.NODE_ENV === 'development') {
app.use(errorhandler());
//}
return app;
}
module.exports = create;