-
Notifications
You must be signed in to change notification settings - Fork 71.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from nightscout/dev
Dev
- Loading branch information
Showing
272 changed files
with
31,268 additions
and
3,835 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Don't include the .git history in the Docker image: | ||
.git | ||
|
||
# Items from .gitignore | ||
bower_components/ | ||
node_modules/ | ||
bundle/bundle.out.js | ||
.idea/ | ||
*.iml | ||
my.env | ||
*.env | ||
static/bower_components/ | ||
.*.sw? | ||
.DS_Store | ||
.vagrant | ||
/iisnode | ||
coverage/ | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ static/bower_components/ | |
coverage/ | ||
|
||
npm-debug.log | ||
*.heapsnapshot | ||
|
||
/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
8.1.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
language: node_js | ||
sudo: false | ||
sudo: required | ||
node_js: | ||
- "0.10" | ||
- "0.12" | ||
services: mongodb | ||
- 6 | ||
matrix: | ||
fast_finish: true | ||
services: | ||
- mongodb | ||
- docker | ||
script: make travis | ||
after_success: | ||
- nvm version | ||
- if [[ ! -z "$DOCKER_USER" ]]; then docker login -u ${DOCKER_USER} -p ${DOCKER_PASS} && git checkout -- . && git clean -fd . && make docker_release; fi | ||
after_script: make report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
Copyright (C) 2015 The Nightscout Foundation, http://www.nightscoutfoundation.org | ||
|
||
We track contributions on a per-patch basis using git. | ||
Please see our published git log: | ||
* https://github.com/nightscout/cgm-remote-monitor/commits/master | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM node:8.1.4 | ||
|
||
MAINTAINER Nightscout Contributors | ||
|
||
RUN apt-get update && \ | ||
apt-get -y dist-upgrade | ||
|
||
RUN mkdir -p /opt/app | ||
ADD . /opt/app | ||
WORKDIR /opt/app | ||
|
||
RUN npm install && \ | ||
npm run postinstall && \ | ||
npm run env | ||
|
||
EXPOSE 1337 | ||
|
||
CMD ["node", "server.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,166 @@ | ||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
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 prettyjson = require('prettyjson'); | ||
|
||
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); | ||
}})); | ||
// app.use(bodyParser({limit: 1048576 * 50, extended: true })); | ||
function create(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 (env.api_secret) { | ||
// console.log("API_SECRET", env.api_secret); | ||
//} | ||
app.use('/api/v1', bodyParser({limit: 1048576 * 50 }), api); | ||
if (ctx.bootErrors && ctx.bootErrors.length > 0) { | ||
app.get('*', require('./lib/booterror')(ctx)); | ||
return app; | ||
} | ||
|
||
if (env.settings.isEnabled('cors')) { | ||
var allowOrigin = _.get(env, 'extendedSettings.cors.allowOrigin') || '*'; | ||
console.info('Enabled CORS, allow-origin:', allowOrigin); | ||
app.use(function allowCrossDomain(req, res, next) { | ||
res.header('Access-Control-Allow-Origin', allowOrigin); | ||
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); | ||
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With'); | ||
|
||
// pebble data | ||
app.get('/pebble', ctx.pebble); | ||
// intercept OPTIONS method | ||
if ('OPTIONS' === req.method) { | ||
res.send(200); | ||
} else { | ||
next(); | ||
} | ||
}); | ||
} | ||
|
||
// expose swagger.yaml | ||
app.get('/swagger.yaml', function (req, res) { | ||
res.sendFile(__dirname + '/swagger.yaml'); | ||
}); | ||
/////////////////////////////////////////////////// | ||
// api and json object variables | ||
/////////////////////////////////////////////////// | ||
var api = require('./lib/api/')(env, ctx); | ||
var ddata = require('./lib/data/endpoints')(env, ctx); | ||
|
||
//app.get('/package.json', software); | ||
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 })); | ||
|
||
// 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}); | ||
//if (env.api_secret) { | ||
// console.log("API_SECRET", env.api_secret); | ||
//} | ||
app.use('/api/v1', bodyParser({ | ||
limit: 1048576 * 50 | ||
}), api); | ||
|
||
// serve the static content | ||
app.use(staticFiles); | ||
app.use('/api/v2/properties', ctx.properties); | ||
app.use('/api/v2/authorization', ctx.authorization.endpoints); | ||
app.use('/api/v2/ddata', ddata); | ||
|
||
var bundle = require('./bundle')(); | ||
app.use(bundle); | ||
// pebble data | ||
app.get('/pebble', ctx.pebble); | ||
|
||
// Handle errors with express's errorhandler, to display more readable error messages. | ||
var errorhandler = require('errorhandler'); | ||
//if (process.env.NODE_ENV === 'development') { | ||
// expose swagger.yaml | ||
app.get('/swagger.yaml', function(req, res) { | ||
res.sendFile(__dirname + '/swagger.yaml'); | ||
}); | ||
|
||
if (env.settings.isEnabled('dumps')) { | ||
var heapdump = require('heapdump'); | ||
app.get('/api/v2/dumps/start', function(req, res) { | ||
var path = new Date().toISOString() + '.heapsnapshot'; | ||
path = path.replace(/:/g, '-'); | ||
console.info('writing dump to', path); | ||
heapdump.writeSnapshot(path); | ||
res.send('wrote dump to ' + path); | ||
}); | ||
} | ||
|
||
|
||
//app.get('/package.json', software); | ||
|
||
// Allow static resources to be cached for week | ||
var maxAge = 7 * 24 * 60 * 60 * 1000; | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
maxAge = 10; | ||
console.log('Development environment detected, setting static file cache age to 10 seconds'); | ||
|
||
app.get('/nightscout.appcache', function(req, res) { | ||
res.sendStatus(404); | ||
}); | ||
} | ||
|
||
//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: maxAge | ||
}); | ||
|
||
// serve the static content | ||
app.use(staticFiles); | ||
|
||
var tmpFiles = express.static('tmp', { | ||
maxAge: maxAge | ||
}); | ||
|
||
// serve the static content | ||
app.use(tmpFiles); | ||
|
||
if (process.env.NODE_ENV !== 'development') { | ||
|
||
console.log('Production environment detected, enabling Minify'); | ||
|
||
var minify = require('express-minify'); | ||
var myUglifyJS = require('uglify-js'); | ||
var myCssmin = require('cssmin'); | ||
|
||
app.use(minify({ | ||
js_match: /\.js/, | ||
css_match: /\.css/, | ||
sass_match: /scss/, | ||
less_match: /less/, | ||
stylus_match: /stylus/, | ||
coffee_match: /coffeescript/, | ||
json_match: /json/, | ||
uglifyJS: myUglifyJS, | ||
cssmin: myCssmin, | ||
cache: __dirname + '/cache', | ||
onerror: undefined, | ||
})); | ||
|
||
} | ||
|
||
// if this is dev environment, package scripts on the fly | ||
// if production, rely on postinstall script to run packaging for us | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
|
||
var webpack = require("webpack"); | ||
var webpack_conf = require('./webpack.config'); | ||
|
||
webpack(webpack_conf, function(err, stats) { | ||
|
||
var json = stats.toJson() // => webpack --json | ||
|
||
var options = { | ||
noColor: true | ||
}; | ||
|
||
console.log(prettyjson.render(json.errors, options)); | ||
console.log(prettyjson.render(json.assets, options)); | ||
|
||
}); | ||
} | ||
|
||
// 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; | ||
//} | ||
return app; | ||
} | ||
module.exports = create; | ||
|
||
module.exports = create; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.