mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
|
|
var express = require('express');
|
|
var compression = require('compression');
|
|
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.
|
|
|
|
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);
|
|
}}));
|
|
|
|
//if (env.api_secret) {
|
|
// console.log("API_SECRET", env.api_secret);
|
|
//}
|
|
app.use('/api/v1', api);
|
|
|
|
|
|
// pebble data
|
|
app.get('/pebble', ctx.pebble);
|
|
|
|
//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.
|
|
|
|
// 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;
|
|
|