diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000000..ff3059c3f09 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["@babel/preset-env"] +} \ No newline at end of file diff --git a/.bowerrc b/.bowerrc deleted file mode 100644 index c2587b247fc..00000000000 --- a/.bowerrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "directory": "./static/bower_components" -} diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000000..974a562c7c6 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,23 @@ +module.exports = { + "plugins": [ ], + "extends": [ + "eslint:recommended" + ], + "parser": "babel-eslint", + "env": { + "browser": true, + "commonjs": true, + "es6": true, + "node": true, + "mocha": true, + "jquery": true + }, + "rules": { + "no-unused-vars": [ + "error", + { + "varsIgnorePattern": "should|expect" + } + ] + } + }; \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/--bug-report.md b/.github/ISSUE_TEMPLATE/--bug-report.md new file mode 100644 index 00000000000..b0d61217880 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/--bug-report.md @@ -0,0 +1,30 @@ +--- +name: "\U0001F41BBug report" +about: Create a report to help us improve things +label: bug + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Your setup information** +- What version of Nightscout (e.g. 0.10.3) +- What type of CGM, and how do you get your data there? (e.g. G4 and ShareBridge, or wired receiver, etc.) +- Is your issue specific to a browser (Firefox/Safari/Chrome?) or a device (Android phone, etc.)? + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/--feature-request--.md b/.github/ISSUE_TEMPLATE/--feature-request--.md new file mode 100644 index 00000000000..a94a261abf8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/--feature-request--.md @@ -0,0 +1,17 @@ +--- +name: "\U0001F4A1Feature request\U0001F4A1" +about: Suggest an idea for this project + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/--individual-troubleshooting-help.md b/.github/ISSUE_TEMPLATE/--individual-troubleshooting-help.md new file mode 100644 index 00000000000..ff6e27b7682 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/--individual-troubleshooting-help.md @@ -0,0 +1,16 @@ +--- +name: "\U0001F198Individual troubleshooting help" +about: Getting help with your own individual setup of Nightscout + +--- + +Having issues getting Nightscout up and running? Instead of creating an issue here, please use one of the existing support channels for Nightscout. + +The main support channel is on Facebook: please join the CGM In The Cloud Facebook group (https://www.facebook.com/groups/cgminthecloud) and start a post there. + +**Suggestions to include in your post when you are asking for help:** +1. Include what you are trying to do: ("*I am trying to set up Nightscout for the first time.*") +2. Include which step you are on and what the problem is: ("*I deployed on Heroku, but I'm not seeing any BG data.*") +3. If possible, include a link to the version of documentation you are following ("*I'm following the OpenAPS Nightscout setup docs (https://openaps.readthedocs.io/en/latest/docs/While%20You%20Wait%20For%20Gear/nightscout-setup.html#nightscout-setup-with-heroku)*") + +Other places you can find support and assistance for Nightscout include Gitter's [nightscout/public](https://gitter.im/nightscout/public) channel. diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000000..23cc61e5ef7 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,32 @@ +name: CI test + +on: [push] + +jobs: + build: + + runs-on: ubuntu-16.04 + + strategy: + matrix: + node-version: [10.x, 12.x] + + steps: + - uses: actions/checkout@v1 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: npm install + - name: Install MongoDB + run: | + wget -qO - https://www.mongodb.org/static/pgp/server-3.6.asc | sudo apt-key add - + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list + sudo apt-get update + sudo apt-get install -y mongodb-org + sudo apt-get install -y --allow-downgrades mongodb-org=3.6.14 mongodb-org-server=3.6.14 mongodb-org-shell=3.6.14 mongodb-org-mongos=3.6.14 mongodb-org-tools=3.6.14 + - name: Start MongoDB + run: sudo systemctl start mongod + - name: Run tests + run: npm run-script test-ci diff --git a/.gitignore b/.gitignore index 2cb28800650..1cf7ab06f2f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,8 @@ bundle/bundle.out.js .idea/ *.iml my.env +my.*.env -*.env static/bower_components/ .*.sw? .DS_Store @@ -24,3 +24,9 @@ npm-debug.log *.heapsnapshot /tmp +/.vs +/cgm-remote-monitor.njsproj +/cgm-remote-monitor.sln +/obj/Debug +/bin +/*.bat diff --git a/.jsbeautifyrc b/.jsbeautifyrc new file mode 100644 index 00000000000..1c15d3872ce --- /dev/null +++ b/.jsbeautifyrc @@ -0,0 +1,16 @@ +{ + "indent_size": 2 + , "indent_char": " " + , "comma_first": true + , "keep-array-indentation": true + , "space_after_named_function": true + , "space_after_anon_function": true + , "end_with_newline": true + , "brace_style": "collapse,preserve-inline" + , "space_in_brace": true + , "space-in-paren": false + , "break-chained-methods": false + , "max-preserve-newlines": 2 + , "space-after-anon-function": false + , "indent-empty-lines": false +} diff --git a/.nvmrc b/.nvmrc index ed13033b848..89da89da65c 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -8.11.x +10.16.0 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index d8ff4c865ff..78b056b8dbc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,30 @@ -language: node_js -os: osx -node_js: - - "8" -before_install: - - if [[ `npm --version` != "5.8.0" ]]; then npm install -g npm@latest; npm --version; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi - # https://github.com/Homebrew/homebrew-core/issues/26358 - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew unlink python; fi - # "brew install" can succeed but return 1 if it has "caveats". - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install mongodb || true; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew services start mongodb; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install docker || true; fi +sudo: required +dist: xenial + +node_js-steps: &node_js-steps + language: node_js + before_install: + - if [[ `npm --version` != "6.4.1" ]]; then npm install -g npm@latest; npm --version; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi + # https://github.com/Homebrew/homebrew-core/issues/26358 + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew unlink python; fi + # "brew install" can succeed but return 1 if it has "caveats". + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install mongodb || true; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew services start mongodb; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install docker || true; fi + 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 + services: + - mongodb + - docker 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 + allow_failures: + node_js: "node" + include: + - node_js: "10" + <<: *node_js-steps + - node_js: "12" # Latest Node is not supported, and recommend, but we'll test it to know incompatibility issues + <<: *node_js-steps diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5be3a99d625..c8e87e2db4a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,26 +3,29 @@ **Table of Contents** - [Contributing to cgm-remote-monitor](#contributing-to-cgm-remote-monitor) - - [Design](#design) + - [Design & new features](#design--new-features) - [Develop on `dev`](#develop-on-dev) - [Style Guide](#style-guide) - [Create a prototype](#create-a-prototype) - [Submit a pull request](#submit-a-pull-request) + - [Bug fixing](#bug-fixing) - [Comments and issues](#comments-and-issues) - [Co-ordination](#co-ordination) - [Other Dev Tips](#other-dev-tips) + - [List of Contributors](#list-of-contributors) + - [Core developers, contributing developers, coordinators and documentation writers](#core-developers-contributing-developers-coordinators-and-documentation-writers) + - [Plugin contributors](#plugin-contributors) + - [Translators](#translators) + - [List of all contributors](#list-of-all-contributors) - # Contributing to cgm-remote-monitor [![Build Status][build-img]][build-url] [![Dependency Status][dependency-img]][dependency-url] [![Coverage Status][coverage-img]][coverage-url] -[![Gitter chat][gitter-img]][gitter-url] -[![Stories in Ready][ready-img]][waffle] -[![Stories in Progress][progress-img]][waffle] +[![Discord chat][discord-img]][discord-url] [build-img]: https://img.shields.io/travis/nightscout/cgm-remote-monitor.svg [build-url]: https://travis-ci.org/nightscout/cgm-remote-monitor @@ -30,29 +33,52 @@ [dependency-url]: https://david-dm.org/nightscout/cgm-remote-monitor [coverage-img]: https://img.shields.io/coveralls/nightscout/cgm-remote-monitor/master.svg [coverage-url]: https://coveralls.io/r/nightscout/cgm-remote-monitor?branch=master -[gitter-img]: https://img.shields.io/badge/Gitter-Join%20Chat%20%E2%86%92-1dce73.svg -[gitter-url]: https://gitter.im/nightscout/public -[ready-img]: https://badge.waffle.io/nightscout/cgm-remote-monitor.svg?label=ready&title=Ready -[waffle]: https://waffle.io/nightscout/cgm-remote-monitor -[progress-img]: https://badge.waffle.io/nightscout/cgm-remote-monitor.svg?label=in+progress&title=In+Progress +[discord-img]: https://img.shields.io/discord/629952586895851530?label=discord%20chat +[discord-url]: https://discordapp.com/channels/629952586895851530/629952669967974410 + +## Installation for development -## Design +Nightscout is a Node.js application. The basic installation of the software for local purposes is: -Participate in the design process by creating an issue to discuss your -design. +1. Clone the software to your local machine using git +2. Install Node from https://nodejs.org/en/download/ +2. Use `npm` to install Nightscout dependencies by invoking `npm install` in the project directory. Note the + dependency installation has to be done using a non-root user - _do not use root_ for development and hosting + the software! +3. Get a Mongo database by either installing Mongo locally, or get a free cloud account from mLab or MongoDB Atlas. +4. Configure Nightscout by copying `my.env.template` to `my.env` and run it - see the next chapter in the instructions ## Develop on `dev` -We develop on the `dev` branch. -You can get the dev branch checked out using `git checkout dev`. +We develop on the `dev` branch. All new pull requests should be targeted to `dev`. The `master` branch is only used for distributing the latest version of the tested sources. + +You can get the `dev` branch checked out using `git checkout dev`. + +Once checked out, install the dependencies using `npm install`, then copy the included `my.env.template`file to `my.env` and edit the file to include your settings (like the Mongo URL). Leave the `NODE_ENV=development` line intact. Once set, run the site using `npm run dev`. This will start Nightscout in the development mode, with different code packaging rules and automatic restarting of the server using nodemon, when you save changed files on disk. The client also hot-reloads new code in, but it's recommended to reload the website after changes due to the way the plugin sandbox works. + +Note the template sets `INSECURE_USE_HTTP` to `true` to enable the site to work over HTTP in local development. + +If you want to additionaly test the site in production mode, create a file called `my.prod.env` that's a copy of the dev file but with `NODE_ENV=production` and start the site using `npm run prod`. + +## REST API + +Nightscout implements a REST API for data syncronization. The API is documented using Swagger. To access the documentation for the API, run Nightscout locally and load the documentation from /api-docs (or read the associated swagger.json and swagger.yaml files locally). + +Note all dates used to access the API and dates stored in the objects are expected to comply with the ISO-8601 format and be deserializable by the Javascript Date class. Of note here is the dates can contain a plus sign which has a special meaning in URL encoding, so when issuing requests that place dates to the URL, take special care to ensure the data is properly URL encoded. + +## Design & new features + +If you intend to add a new feature, please allow the community to participate in the design process by creating an issue to discuss your design. For new features, the issue should describe what use cases the new feature intends to solve, or which existing use cases are being improved. + +Note Nightscout has a plugin architecture for adding new features. We expect most code for new features live inside a Plugin, so the code retains a clear separation of concerns. If the Plugin API doesn't implement all features you need to implement your feature, please discuss with us on adding those features to the API. Note new features should under almost no circumstances require changes to the existing plugins. ## Style Guide -Some simple rules, that will make it easier to maintain our codebase: +Some simple rules that will make it easier to maintain our codebase: -* All indenting should use 2 space where possible (js, css, html, etc) -* A space before function parameters, such as: `function boom (name, callback) { }`, this makes searching for calls easier -* Name your callback functions, such as `boom('the name', function afterBoom ( result ) { }` +* All indenting should use 2 space where possible (js, css, html, etc). +* Include a space before function parameters, such as: `function boom (name, callback) { }`, this makes searching for function calls easier. +* Name your callback functions, such as `boom('the name', function afterBoom ( result ) { }`. * Don't include author names in the header of your files, if you need to give credit to someone else do it in the commit comment. * Use single quotes. * Use the comma first style, for example: @@ -65,58 +91,183 @@ Some simple rules, that will make it easier to maintain our codebase: }; ``` +If in doubt, format your code with `js-beautify --indent-size 2 --comma-first --keep-array-indentation` + ## Create a prototype -Fork cgm-remote-monitor and create a branch. -You can create a branch using `git checkout -b wip/add-my-widget`. -This creates a new branch called `wip/add-my-widget`. The `wip` -stands for work in progress and is a common prefix so that when know -what to expect when reviewing many branches. +Fork cgm-remote-monitor and create a branch. You can create a branch using `git checkout -b wip/add-my-widget`. This creates a new branch called `wip/add-my-widget`. The "`wip`" stands for work-in-progress and is a common prefix so that we know what to expect when reviewing many branches. ## Submit a pull request -When you are done working with your prototype, it can be tempting to -post on popular channels such as Facebook. We encourage contributors -to submit their code for review, debate, and release before announcing -features on social media. +When you are done working with your prototype, it can be tempting to post on popular channels such as Facebook. We encourage contributors to submit their code for review, debate, and release before announcing features on social media. + +This can be done by checking your code `git commit -avm 'my improvements are here'`, the branch you created back to your own fork. This will probably look something like `git push -u origin wip/add-my-widget`. + +Now that the commits are available on github, you can click on the compare buttons on your fork to create a pull request. Make sure to select [Nightscout's `dev` branch](https://github.com/nightscout/cgm-remote-monitor/tree/dev). + +We assume all new Pull Requests are at least smoke tested by the author and all code in the PR actually works. Please include a description of what the features do and rationalize why the changes are needed. + +If you add any new NPM module dependencies, you have to rationalize why they are needed - we prefer pull requests that reduce dependencies, not add them. Before releasing a a new version, we check with `npm audit` if our dependencies don't have known security issues. -This can be done by checking your code `git commit -avm 'my -improvements are here'`, the branch you created back to your own +When adding new features that add configuration options, please ensure the `README` document is amended with information on the new configuration. + +## Bug fixing + +If you've fixed a bug, please consider adding a unit test to the `/tests` folder that reproduces the original bug without the change. + +Try to identify the root cause of the issue and fix the issue. Pull requests that simply add null checks to hide issues are unlikely to be accepted. + +This can be done by committing your code `git commit -avm 'my +improvements are here'`, and pushing it to the branch you created on your own fork. This will probably look something like `git push -u origin wip/add-my-widget`. -Now that the commits are available on github, you can click on the -compare buttons on your fork to create a pull request. Make sure to -select [Nightscout's `dev` branch](https://github.com/nightscout/cgm-remote-monitor/tree/dev). +Please include instructions how to test the changes. ## Comments and issues -We encourage liberal use of the comments, including images where -appropriate. +We encourage liberal use of the comments, including images where appropriate. ## Co-ordination -Most cgm-remote-monitor hackers use github's ticketing system, along with Facebook cgm-in-the-cloud, and -gitter. +We primarily use GitHub's ticketing system for discussing PRs and bugs, and [Discord][discord-url] for general development chatter. -We use git-flow, with `master` as our production, stable branch, and -`dev` is used to queue up for upcoming releases. Everything else is -done on branches, hopefully with names that indicate what to expect. +We use git-flow, with `master` as our production, stable branch, and `dev` is used to queue up for upcoming releases. Everything else is done on branches, hopefully with names that indicate what to expect. -Once `dev` has been reviewed and people feel it's time to release, we -follow the git-flow release process, which creates a new tag and bumps -the version correctly. See sem-ver for versioning strategy. +Once `dev` has been reviewed and people feel it's time to release, we follow the git-flow release process, which creates a new tag and bumps the version correctly. See sem-ver for versioning strategy. -Every commit is tested by travis. We encourage adding tests to -validate your design. We encourage discussing your use cases to help -everyone get a better understanding of your design. +Every commit is tested by travis. We encourage adding tests to validate your design. We encourage discussing your use cases to help everyone get a better understanding of your design. ## Other Dev Tips -* Join the [Gitter chat][gitter-url] -* Get a local dev environment setup if you haven't already -* Try breaking up big features/improvements into small parts. It's much easier to accept small PR's -* Create tests for your new code, and for the old code too. We are aiming for a full test coverage. -* If your going to be working in old code that needs lots of reformatting consider doing the clean as a separate PR. -* If you can find others to help test your PR is will help get them merged in sooner. +* Join the [Discord chat][discord-url]. +* Get a local dev environment setup if you haven't already. +* Try breaking up big features/improvements into small parts. It's much easier to accept small PR's. +* Create tests for your new code as well as the old code. We are aiming for a full test coverage. +* If you're going to be working in old code that needs lots of reformatting, consider doing it as a separate PR. +* If you can find others to help test your PR, it will help get them merged in sooner. +## List of Contributors + +We welcome new contributors. We do not only need core contributors. Regular or one time contributors are welcomed as well. +Also if you can't code, it's possible to contribute by improving the documentation or by translating Nightscout in your own language + +### Core developers, contributing developers, coordinators and documentation writers + +[@andrew-warrington]: https://github.com/andrew-warrington +[@apanasef]: https://github.com/apanasef +[@bewest]: https://github.com/bewest +[@danamlewis]: https://github.com/danamlewis +[@diabetlum]: https://github.com/diabetlum +[@herzogmedia]: https://github.com/herzogmedia +[@jamieowendexcom ]: https://github.com/jamieowendexcom +[@janrpn]: https://github.com/janrpn +[@jasoncalabrese]: https://github.com/jasoncalabrese +[@jizhongwen]: https://github.com/jizhongwen +[@jpcunningh]: https://github.com/jpcunningh +[@jweismann]: https://github.com/jweismann +[@komarserjio]: https://github.com/komarserjio +[@LuminaryXion]: https://github.com/LuminaryXion +[@mcdafydd]: https://github.com/mcdafydd +[@mdomox]: https://github.com/mdomox +[@MilosKozak]: https://github.com/MilosKozak +[@oteroos]: https://github.com/oteroos +[@PieterGit]: https://github.com/PieterGit +[@rarneson]: https://github.com/rarneson +[@rickfriele]: https://github.com/rickfriele +[@scottleibrand]: https://github.com/scottleibrand +[@sulkaharo]: https://github.com/sulkaharo +[@tynbendad]: https://github.com/tynbendad +[@unsoluble]: https://github.com/unsoluble +[@viderehh]: https://github.com/viderehh +[@OpossumGit]: https://github.com/OpossumGit + +| Contribution area | List of contributors | +| ------------------------------------- | ---------------------------------- | +| Core developers: | [@jasoncalabrese] [@MilosKozak] [@PieterGit] [@sulkaharo] | +| Former Core developers: (not active): | [@bewest] | +| Contributing developers: | [@jpcunningh] [@scottleibrand] [@komarserjio] [@jweismann] | +| Release coordination 0.10.x: | [@PieterGit] [@sulkaharo] | +| Release coordination 0.11.x: | [@PieterGit] | +| Issue/Pull request coordination: | Please volunteer | +| Cleaning up git fork spam: | Please volunteer | +| Documentation writers: | [@andrew-warrington] [@unsoluble] [@tynbendad] [@danamlewis] [@rarneson] | + +### Plugin contributors + +| Contribution area | List of developers | List of testers +| ------------------------------------- | -------------------- | -------------------- | +| [`alexa` (Amazon Alexa)](README.md#alexa-amazon-alexa)| [@inventor96] | Please volunteer | +| [`ar2` (AR2 Forecasting)](README.md#ar2-ar2-forecasting)| Please volunteer | Please volunteer | +| [`basal` (Basal Profile)](README.md#basal-basal-profile)| Please volunteer | Please volunteer | +| [`boluscalc` (Bolus Wizard)](README.md#boluscalc-bolus-wizard)| Please volunteer | Please volunteer | +| [`bridge` (Share2Nightscout bridge)](README.md#bridge-share2nightscout-bridge)| Please volunteer | Please volunteer | +| [`bwp` (Bolus Wizard Preview)](README.md#bwp-bolus-wizard-preview)| Please volunteer | Please volunteer | +| [`cage` (Cannula Age)](README.md#cage-cannula-age)| [@jpcunningh] | Please volunteer | +| [`careportal` (Careportal)](README.md#careportal-careportal)| Please volunteer | Please volunteer | +| [`cob` (Carbs-on-Board)](README.md#cob-carbs-on-board)| Please volunteer | Please volunteer | +| [`cors` (CORS)](README.md#cors-cors)| Please volunteer | Please volunteer | +| [`delta` (BG Delta)](README.md#delta-bg-delta)| Please volunteer | Please volunteer | +| [`devicestatus` (Device Status)](README.md#devicestatus-device-status)| Please volunteer | Please volunteer | +| [`direction` (BG Direction)](README.md#direction-bg-direction)| Please volunteer | Please volunteer | +| [`errorcodes` (CGM Error Codes)](README.md#errorcodes-cgm-error-codes)| Please volunteer | Please volunteer | +| [`food` (Custom Foods)](README.md#food-custom-foods)| Please volunteer | Please volunteer | +| [`googlehome` (Google Home/DialogFlow)](README.md#googlehome-google-homedialogflow)| [@mdomox] [@rickfriele] [@inventor96] | [@mcdafydd] [@oteroos] [@jamieowendexcom] | +| [`iage` (Insulin Age)](README.md#iage-insulin-age)| Please volunteer | Please volunteer | +| [`iob` (Insulin-on-Board)](README.md#iob-insulin-on-board)| Please volunteer | Please volunteer | +| [`loop` (Loop)](README.md#loop-loop)| Please volunteer | Please volunteer | +| [`mmconnect` (MiniMed Connect bridge)](README.md#mmconnect-minimed-connect-bridge)| Please volunteer | Please volunteer | +| [`openaps` (OpenAPS)](README.md#openaps-openaps)| Please volunteer | Please volunteer | +| [`profile` (Treatment Profile)](README.md#profile-treatment-profile)| Please volunteer | Please volunteer | +| [`pump` (Pump Monitoring)](README.md#pump-pump-monitoring)| Please volunteer | Please volunteer | +| [`rawbg` (Raw BG)](README.md#rawbg-raw-bg)| [@jpcunningh] | Please volunteer | +| [`sage` (Sensor Age)](README.md#sage-sensor-age)| [@jpcunningh] | Please volunteer | +| [`simplealarms` (Simple BG Alarms)](README.md#simplealarms-simple-bg-alarms)| Please volunteer | Please volunteer | +| [`speech` (Speech)](README.md#speech-speech)| [@sulkaharo] | Please volunteer | +| [`timeago` (Time Ago)](README.md#timeago-time-ago)| Please volunteer | Please volunteer | +| [`treatmentnotify` (Treatment Notifications)](README.md#treatmentnotify-treatment-notifications)| Please volunteer | Please volunteer | +| [`upbat` (Uploader Battery)](README.md#upbat-uploader-battery)| [@jpcunningh] | Please volunteer | +| [`xdrip-js` (xDrip-js)](README.md#xdrip-js-xdrip-js)| [@jpcunningh] | Please volunteer | + +### Translators + +See `/translations` of your Nightscout, to view the current translation coverage and the missing items. +Languages with less than 90% coverage will be removed in a future Nightscout versions. + +| Language | List of translators | Status +| ------------- | -------------------- |-------------------- | +| Български (`bg`) |Please volunteer| OK | +| Čeština (`cs`) |Please volunteer|OK | +| Deutsch (`de`) |[@viderehh] [@herzogmedia] |OK | +| Dansk (`dk`) | [@janrpn] |OK | +| Ελληνικά (`el`)|Please volunteer|Needs attention: 68.5%| +| English (`en`)|Please volunteer|OK| +| Español (`es`) |Please volunteer|OK| +| Suomi (`fi`)|[@sulkaharo] |OK| +| Français (`fr`)|Please volunteer|OK| +| עברית (`he`)| [@jakebloom] |OK| +| Hrvatski (`hr`)|[@OpossumGit]|OK| +| Italiano (`it`)|Please volunteer|OK| +| 日本語 (`ja`)|[@LuminaryXion]|Working on this| +| 한국어 (`ko`)|Please volunteer|Needs attention: 80.6%| +| Norsk (Bokmål) (`nb`)|Please volunteer|OK| +| Nederlands (`nl`)|[@PieterGit]|OK| +| Polski (`pl`)|Please volunteer|OK| +| Português (Brasil) (`pt`)|Please volunteer|OK| +| Română (`ro`)|Please volunteer|OK| +| Русский (`ru`)|[@apanasef]|OK| +| Slovenčina (`sk`)|Please volunteer|OK| +| Svenska (`sv`)|Please volunteer|OK| +| Türkçe (`tr`)|[@diabetlum]|OK| +| 中文(简体) (`zh_cn`) | [@jizhongwen]|OK| +| 中文(繁體) (`zh_tw`) | [@jizhongwen]|Needs attention: 25.0% +| 日本語 (`ja_jp`) | [@LuminaryXion]| + + +### List of all contributors +| Contribution area | List of contributors | +| ------------------------------------- | -------------------- | +| All active developers: | [@jasoncalabrese] [@jpcunningh] [@jweismann] [@komarserjio] [@mdomox] [@MilosKozak] [@PieterGit] [@rickfriele] [@sulkaharo] [@unsoluble] +| All active testers/documentors: | [@danamlewis] [@jamieowendexcom] [@mcdafydd] [@oteroos] [@rarneson] [@tynbendad] [@unsoluble] +| All active translators: | [@apanasef] [@jizhongwen] [@viderehh] [@herzogmedia] [@LuminaryXion] [@OpossumGit] + diff --git a/Dockerfile.example b/Dockerfile.example index d4c13c0ecd9..89a43f43c15 100644 --- a/Dockerfile.example +++ b/Dockerfile.example @@ -1,17 +1,17 @@ -FROM node:8.9.1 +FROM node:10-alpine MAINTAINER Nightscout Contributors -RUN apt-get update && \ - apt-get -y dist-upgrade - RUN mkdir -p /opt/app ADD . /opt/app WORKDIR /opt/app +RUN chown -R node:node /opt/app +USER node RUN npm install && \ npm run postinstall && \ - npm run env + npm run env && \ + npm audit fix EXPOSE 1337 diff --git a/Makefile b/Makefile index 7829258bd58..1ca626ab88c 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,8 @@ MOCHA=./node_modules/mocha/bin/_mocha # Pinned from dependency list. ISTANBUL=./node_modules/.bin/istanbul ANALYZED=./coverage/lcov.info -export CODACY_REPO_TOKEN=e29ae5cf671f4f918912d9864316207c +# Following token deprecated +# export CODACY_REPO_TOKEN=e29ae5cf671f4f918912d9864316207c DOCKER_IMAGE=nightscout/cgm-remote-monitor-travis @@ -42,7 +43,7 @@ report: test_onebyone: python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);' - $(foreach var,$(wildcard tests/*.js),${MONGO_SETTINGS} ${MOCHA} --timeout 30000 --exit --bail -R tap $(var);) + for var in tests/*.js; do ${MONGO_SETTINGS} ${MOCHA} --timeout 30000 --exit --bail -R tap $$var; done | tap-set-exit test: ${MONGO_SETTINGS} ${MOCHA} --timeout 30000 --exit --bail -R tap ${TESTS} @@ -51,7 +52,7 @@ travis: python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);' # NODE_ENV=test ${MONGO_SETTINGS} \ # ${ISTANBUL} cover ${MOCHA} --report lcovonly -- --timeout 5000 -R tap ${TESTS} - $(foreach var,$(wildcard tests/*.js),${MONGO_SETTINGS} ${MOCHA} --timeout 30000 --exit --bail -R tap $(var);) + for var in tests/*.js; do ${MONGO_SETTINGS} ${MOCHA} --timeout 30000 --exit --bail -R tap $$var; done docker_release: # Get the version from the package.json file diff --git a/README.md b/README.md index 93dd92d17fd..f4a0452dd9d 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ Nightscout Web Monitor (a.k.a. cgm-remote-monitor) [![Dependency Status][dependency-img]][dependency-url] [![Coverage Status][coverage-img]][coverage-url] [![Codacy Badge][codacy-img]][codacy-url] -[![Gitter chat][gitter-img]][gitter-url] +[![Discord chat][discord-img]][discord-url] -[![Deploy to Azure](http://azuredeploy.net/deploybutton.png)](https://azuredeploy.net/) [![Deploy to Heroku][heroku-img]][heroku-url] +[![Deploy to Azure](http://azuredeploy.net/deploybutton.png)](https://azuredeploy.net/) [![Deploy to Heroku][heroku-img]][heroku-url] [![Update your site][update-img]][update-fork] This acts as a web-based CGM (Continuous Glucose Monitor) to allow multiple caregivers to remotely view a patient's glucose data in @@ -35,10 +35,12 @@ Community maintained fork of the [coverage-url]: https://coveralls.io/github/nightscout/cgm-remote-monitor?branch=master [codacy-img]: https://www.codacy.com/project/badge/f79327216860472dad9afda07de39d3b [codacy-url]: https://www.codacy.com/app/Nightscout/cgm-remote-monitor -[gitter-img]: https://img.shields.io/badge/Gitter-Join%20Chat%20%E2%86%92-1dce73.svg -[gitter-url]: https://gitter.im/nightscout/public +[discord-img]: https://img.shields.io/discord/629952586895851530?label=discord%20chat +[discord-url]: https://discord.gg/rTKhrqz [heroku-img]: https://www.herokucdn.com/deploy/button.png [heroku-url]: https://heroku.com/deploy +[update-img]: update.png +[update-fork]: http://nightscout.github.io/pages/update-fork/ [original]: https://github.com/rnpenguin/cgm-remote-monitor @@ -46,6 +48,11 @@ Community maintained fork of the **Table of Contents** - [Install](#install) + - [Supported configurations:](#supported-configurations) + - [Minimum browser requirements for viewing the site:](#minimum-browser-requirements-for-viewing-the-site) + - [Windows installation software requirements:](#windows-installation-software-requirements) + - [Installation notes for users with nginx or Apache reverse proxy for SSL/TLS offloading:](#installation-notes-for-users-with-nginx-or-apache-reverse-proxy-for-ssltls-offloading) + - [Installation notes for Microsoft Azure, Windows:](#installation-notes-for-microsoft-azure-windows) - [Usage](#usage) - [Updating my version?](#updating-my-version) - [What is my mongo string?](#what-is-my-mongo-string) @@ -58,7 +65,7 @@ Community maintained fork of the - [Alarms](#alarms) - [Core](#core) - [Predefined values for your browser settings (optional)](#predefined-values-for-your-browser-settings-optional) - - [Views](#views) + - [Predefined values for your server settings (optional)](#predefined-values-for-your-server-settings-optional) - [Plugins](#plugins) - [Default Plugins](#default-plugins) - [`delta` (BG Delta)](#delta-bg-delta) @@ -70,7 +77,7 @@ Community maintained fork of the - [`ar2` (AR2 Forecasting)](#ar2-ar2-forecasting) - [`simplealarms` (Simple BG Alarms)](#simplealarms-simple-bg-alarms) - [`profile` (Treatment Profile)](#profile-treatment-profile) - - [Advanced Plugins](#advanced-plugins) + - [Advanced Plugins:](#advanced-plugins) - [`careportal` (Careportal)](#careportal-careportal) - [`boluscalc` (Bolus Wizard)](#boluscalc-bolus-wizard) - [`food` (Custom Foods)](#food-custom-foods) @@ -81,6 +88,7 @@ Community maintained fork of the - [`cage` (Cannula Age)](#cage-cannula-age) - [`sage` (Sensor Age)](#sage-sensor-age) - [`iage` (Insulin Age)](#iage-insulin-age) + - [`bage` (Battery Age)](#bage-battery-age) - [`treatmentnotify` (Treatment Notifications)](#treatmentnotify-treatment-notifications) - [`basal` (Basal Profile)](#basal-basal-profile) - [`bridge` (Share2Nightscout bridge)](#bridge-share2nightscout-bridge) @@ -88,8 +96,11 @@ Community maintained fork of the - [`pump` (Pump Monitoring)](#pump-pump-monitoring) - [`openaps` (OpenAPS)](#openaps-openaps) - [`loop` (Loop)](#loop-loop) - - [`xdrip-js` (xDrip-js)](#xdrip-js-xdrip-js) + - [`override` (Override Mode)](#override-override-mode) + - [`xdripjs` (xDrip-js)](#xdripjs-xdripjs) - [`alexa` (Amazon Alexa)](#alexa-amazon-alexa) + - [`googlehome` (Google Home/DialogFLow)](#googlehome-google-homedialogflow) + - [`speech` (Speech)](#speech-speech) - [`cors` (CORS)](#cors-cors) - [Extended Settings](#extended-settings) - [Pushover](#pushover) @@ -104,19 +115,34 @@ Community maintained fork of the # Install -Supported configurations: +## Supported configurations: -If you plan to use Nightscout, we recommend using [Heroku](http://openaps.readthedocs.io/en/latest/docs/While%20You%20Wait%20For%20Gear/nightscout-setup.html#nightscout-setup-with-heroku), as Nightscout can reach the usage limits of the free Azure plan and cause it to shut down for hours or days. If you end up needing a paid tier, the $7/mo Heroku plan is also much cheaper than the first paid tier of Azure. Currently, the only added benefit to choosing the $7/mo Heroku plan vs the free Heroku plan is a section showing site use metrics for performance (such as response time). This has limited benefit to the average Nightscout user. In short, Heroku is the free and best option for Nightscout hosting. +If you plan to use Nightscout, we recommend using [Heroku](http://www.nightscout.info/wiki/welcome/set-up-nightscout-using-heroku), as Nightscout can reach the usage limits of the free Azure plan and cause it to shut down for hours or days. If you end up needing a paid tier, the $7/mo Heroku plan is also much cheaper than the first paid tier of Azure. Currently, the only added benefit to choosing the $7/mo Heroku plan vs the free Heroku plan is a section showing site use metrics for performance (such as response time). This has limited benefit to the average Nightscout user. In short, Heroku is the free and best option for Nightscout hosting. -- [Nightscout Setup with Heroku] (http://openaps.readthedocs.io/en/latest/docs/While%20You%20Wait%20For%20Gear/nightscout-setup.html#nightscout-setup-with-heroku) (recommended) -- [Nightscout Setup with Microsoft Azure] (http://www.nightscout.info/wiki/faqs-2/azure-2) (not recommended, please +- [Nightscout Setup with Heroku](http://www.nightscout.info/wiki/welcome/set-up-nightscout-using-heroku) (recommended) +- [Nightscout Setup with Microsoft Azure](http://www.nightscout.info/wiki/faqs-2/azure-2) (not recommended, please [switch from Azure to Heroku](http://openaps.readthedocs.io/en/latest/docs/While%20You%20Wait%20For%20Gear/nightscout-setup.html#switching-from-azure-to-heroku) ) - Linux based install (Debian, Ubuntu, Raspbian) install with own Node.JS and MongoDB install (see software requirements below) - Windows based install with own Node.JS and MongoDB install (see software requirements below) -Software requirements: +## Recommended minimum browser versions for using Nightscout: + +Older versions of the browsers might work, but are untested. + +- Android 4 +- iOS 6 +- Chrome 35 +- Edge 17 +- Firefox 61 +- Opera 12.1 +- Safari 6 (macOS 10.7) +- Internet Explorer: not supported + +Some features may not work with devices/browsers on the older end of these requirements. -- [Node.js](http://nodejs.org/) Latest Node 8 LTS (Node 8.11.3 or later). Use [Install instructions for Node](https://nodejs.org/en/download/package-manager/) or use `setup.sh`) +## Windows installation software requirements: + +- [Node.js](http://nodejs.org/) Latest Node 8 LTS (Node 8.15.1 or later) or Node 10 LTS (Node 10.16.0 or later; Node 10.15.2 works for Azure). Node versions that do not have the latest security patches will not work. Use [Install instructions for Node](https://nodejs.org/en/download/package-manager/) or use `setup.sh`) - [MongoDB](https://www.mongodb.com/download-center?jmp=nav#community) 3.x or later. MongoDB 2.4 is only supported for Raspberry Pi. As a non-root user clone this repo then install dependencies into the root of the project: @@ -125,55 +151,59 @@ As a non-root user clone this repo then install dependencies into the root of th $ npm install ``` -Installation notes for Microsoft Azure, Windows and Node 10: +## Installation notes for users with nginx or Apache reverse proxy for SSL/TLS offloading: + +- Your site redirects insecure connections to `https` by default. If you use a reverse proxy like nginx or Apache to handle the connection security for you, make sure it sets the `X-Forwarded-Proto` header. Otherwise nightscout will be unable to know if it was called through a secure connection and will try to redirect you to the https version. If you're unable to set this Header, you can change the `INSECURE_USE_HTTP` setting in nightscout to true in order to allow insecure connections without being redirected. +- In case you use a proxy. Do not use an external network interfaces for hosting Nightscout. Make sure the unsecure port is not available from a remote network connection +- HTTP Strict Transport Security (HSTS) headers are enabled by default, use settings `SECURE_HSTS_HEADER` and `SECURE_HSTS_HEADER_*` +- See [Predefined values for your server settings](#predefined-values-for-your-server-settings-optional) for more details -- If deploying the software to Microsoft Azure, you must set ** in the app settings for *WEBSITE_NODE_DEFAULT_VERSION* and *SCM_COMMAND_IDLE_TIMEOUT* **before** you deploy the latest Nightscout or the site deployment will likely fail. Other hosting environments do not require this setting. Please use: +## Installation notes for Microsoft Azure, Windows: + +- If deploying the software to Microsoft Azure, you must set ** in the app settings for *WEBSITE_NODE_DEFAULT_VERSION* and *SCM_COMMAND_IDLE_TIMEOUT* **before** you deploy the latest Nightscout or the site deployment will likely fail. Other hosting environments do not require this setting. Additionally, if using the Azure free hosting tier, the installation might fail due to resource constraints imposed by Azure on the free hosting. Please set the following settings to the environment in Azure: ``` -WEBSITE_NODE_DEFAULT_VERSION=8.11.1 +WEBSITE_NODE_DEFAULT_VERSION=10.15.2 SCM_COMMAND_IDLE_TIMEOUT=300 ``` - See [install MongoDB, Node.js, and Nightscouton a single Windows system](https://github.com/jaylagorio/Nightscout-on-Windows-Server). if you want to host your Nightscout outside of the cloud. Although the instructions are intended for Windows Server the procedure is compatible with client versions of Windows such as Windows 7 and Windows 10. -- If you deploy to Windows and want to develop or test you need to install [Cygwin] (https://www.cygwin.com/) (use [setup-x86_64.exe] (https://www.cygwin.com/setup-x86_64.exe) and make sure to install `build-essential` package. Test your configuration by executing `make` and check if all tests are ok. -- There may be some issues with Node 10.6.0 or later with Nightscout. Node 10 support will be in the 0.11 release. Please don't use Nightscout with (Node 9 or) Node 10 at this moment. +- If you deploy to Windows and want to develop or test you need to install [Cygwin](https://www.cygwin.com/) (use [setup-x86_64.exe](https://www.cygwin.com/setup-x86_64.exe) and make sure to install `build-essential` package. Test your configuration by executing `make` and check if all tests are ok. + +# Development + +Want to help with development, or just see how Nightscout works? Great! See [CONTRIBUTING.md](CONTRIBUTING.md) for development-related documentation. # Usage The data being uploaded from the server to the client is from a -MongoDB server such as [mongolab][mongodb]. +MongoDB server such as [mLab][mLab]. -[mongodb]: https://mongolab.com +[mLab]: https://mlab.com/ [autoconfigure]: https://nightscout.github.io/pages/configure/ [mongostring]: https://nightscout.github.io/pages/mongostring/ -[update-fork]: http://nightscout.github.io/pages/update-fork/ ## Updating my version? -The easiest way to update your version of cgm-remote-monitor to our latest -recommended version is to use the [update my fork tool][update-fork]. It even -gives out stars if you are up to date. -## What is my mongo string? - -Try the [what is my mongo string tool][mongostring] to get a good idea of your -mongo string. You can copy and paste the text in the gray box into your -`MONGO_CONNECTION` environment variable. +The easiest way to update your version of cgm-remote-monitor to the latest version is to use the [update tool][update-fork]. A step-by-step guide is available [here][http://www.nightscout.info/wiki/welcome/how-to-update-to-latest-cgm-remote-monitor-aka-cookie]. +To downgrade to an older version, follow [this guide][http://www.nightscout.info/wiki/welcome/how-to-deploy-an-older-version-of-nightscout]. ## Configure my uploader to match Use the [autoconfigure tool][autoconfigure] to sync an uploader to your config. - ## Nightscout API -The Nightscout API enables direct access to your DData without the need for direct Mongo access. +The Nightscout API enables direct access to your data without the need for Mongo access. You can find CGM data in `/api/v1/entries`, Care Portal Treatments in `/api/v1/treatments`, and Treatment Profiles in `/api/v1/profile`. The server status and settings are available from `/api/v1/status.json`. By default the `/entries` and `/treatments` APIs limit results to the the most recent 10 values from the last 2 days. You can get many more results, by using the `count`, `date`, `dateString`, and `created_at` parameters, depending on the type of data you're looking for. +Once you've installed Nightscout, you can access API documentation by loading `/api-docs/` URL in your instance. + #### Example Queries -(replace `http://localhost:1337` with your base url, YOUR-SITE) +(replace `http://localhost:1337` with your own URL) * 100's: `http://localhost:1337/api/v1/entries.json?find[sgv]=100` * Count of 100's in a month: `http://localhost:1337/api/v1/count/entries/where?find[dateString][$gte]=2016-09&find[dateString][$lte]=2016-10&find[sgv]=100` @@ -182,8 +212,7 @@ You can get many more results, by using the `count`, `date`, `dateString`, and ` * Boluses over 2U: `http://localhost:1337/api/v1/treatments.json?find[insulin][$gte]=2` The API is Swagger enabled, so you can generate client code to make working with the API easy. -To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.html or review [swagger.yaml](swagger.yaml). - +To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs/ or review [swagger.yaml](swagger.yaml). ## Environment @@ -191,31 +220,31 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm ### Required - * `MONGO_CONNECTION` - Your mongo uri, for example: `mongodb://sally:sallypass@ds099999.mongolab.com:99999/nightscout` - * `DISPLAY_UNITS` (`mg/dl`) - Choices: `mg/dl` and `mmol`. Setting to `mmol` puts the entire server into `mmol` mode by default, no further settings needed. - * `BASE_URL` - Used for building links to your sites api, ie pushover callbacks, usually the URL of your Nightscout site you may want https instead of http + * `MONGODB_URI` - The connection string for your Mongo database. Something like `mongodb://sally:sallypass@ds099999.mongolab.com:99999/nightscout`. + * `API_SECRET` - A secret passphrase that must be at least 12 characters long. + * `MONGODB_COLLECTION` (`entries`) - The Mongo collection where CGM entries are stored. + * `DISPLAY_UNITS` (`mg/dl`) - Options are `mg/dl` or `mmol/L` (or just `mmol`). Setting to `mmol/L` puts the entire server into `mmol/L` mode by default, no further settings needed. -### Features/Labs +### Features * `ENABLE` - Used to enable optional features, expects a space delimited list, such as: `careportal rawbg iob`, see [plugins](#plugins) below * `DISABLE` - Used to disable default features, expects a space delimited list, such as: `direction upbat`, see [plugins](#plugins) below - * `API_SECRET` - A secret passphrase that must be at least 12 characters long, required to enable `POST` and `PUT`; also required for the Care Portal + * `BASE_URL` - Used for building links to your site's API, i.e. Pushover callbacks, usually the URL of your Nightscout site. * `AUTH_DEFAULT_ROLES` (`readable`) - possible values `readable`, `denied`, or any valid role name. When `readable`, anyone can view Nightscout without a token. Setting it to `denied` will require a token from every visit, using `status-only` will enable api-secret based login. * `IMPORT_CONFIG` - Used to import settings and extended settings from a url such as a gist. Structure of file should be something like: `{"settings": {"theme": "colors"}, "extendedSettings": {"upbat": {"enableAlerts": true}}}` * `TREATMENTS_AUTH` (`on`) - possible values `on` or `off`. Deprecated, if set to `off` the `careportal` role will be added to `AUTH_DEFAULT_ROLES` - ### Alarms - These alarm setting effect all delivery methods (browser, pushover, maker, etc), some settings can be overridden per client (web browser) + These alarm setting affect all delivery methods (browser, Pushover, IFTTT, etc.). Values and settings entered here will be the defaults for new browser views, but will be overridden if different choices are made in the settings UI. * `ALARM_TYPES` (`simple` if any `BG_`* ENV's are set, otherwise `predict`) - currently 2 alarm types are supported, and can be used independently or combined. The `simple` alarm type only compares the current BG to `BG_` thresholds above, the `predict` alarm type uses highly tuned formula that forecasts where the BG is going based on it's trend. `predict` **DOES NOT** currently use any of the `BG_`* ENV's - * `BG_HIGH` (`260`) - must be set using mg/dl units; the high BG outside the target range that is considered urgent - * `BG_TARGET_TOP` (`180`) - must be set using mg/dl units; the top of the target range, also used to draw the line on the chart - * `BG_TARGET_BOTTOM` (`80`) - must be set using mg/dl units; the bottom of the target range, also used to draw the line on the chart - * `BG_LOW` (`55`) - must be set using mg/dl units; the low BG outside the target range that is considered urgent + * `BG_HIGH` (`260`) - the high BG outside the target range that is considered urgent (interprets units based on DISPLAY_UNITS setting) + * `BG_TARGET_TOP` (`180`) - the top of the target range, also used to draw the line on the chart (interprets units based on DISPLAY_UNITS setting) + * `BG_TARGET_BOTTOM` (`80`) - the bottom of the target range, also used to draw the line on the chart (interprets units based on DISPLAY_UNITS setting) + * `BG_LOW` (`55`) - the low BG outside the target range that is considered urgent (interprets units based on DISPLAY_UNITS setting) * `ALARM_URGENT_HIGH` (`on`) - possible values `on` or `off` * `ALARM_URGENT_HIGH_MINS` (`30 60 90 120`) - Number of minutes to snooze urgent high alarms, space separated for options in browser, first used for pushover * `ALARM_HIGH` (`on`) - possible values `on` or `off` @@ -227,10 +256,8 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm * `ALARM_URGENT_MINS` (`30 60 90 120`) - Number of minutes to snooze urgent alarms (that aren't tagged as high or low), space separated for options in browser, first used for pushover * `ALARM_WARN_MINS` (`30 60 90 120`) - Number of minutes to snooze warning alarms (that aren't tagged as high or low), space separated for options in browser, first used for pushover - ### Core - * `MONGO_COLLECTION` (`entries`) - The collection used to store SGV, MBG, and CAL records from your CGM device * `MONGO_TREATMENTS_COLLECTION` (`treatments`) -The collection used to store treatments entered in the Care Portal, see the `ENABLE` env var above * `MONGO_DEVICESTATUS_COLLECTION`(`devicestatus`) - The collection used to store device status information such as uploader battery * `MONGO_PROFILE_COLLECTION`(`profile`) - The collection used to store your profiles @@ -238,19 +265,20 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm * `MONGO_ACTIVITY_COLLECTION`(`activity`) - The collection used to store activity data * `PORT` (`1337`) - The port that the node.js application will listen on. * `HOSTNAME` - The hostname that the node.js application will listen on, null by default for any hostname for IPv6 you may need to use `::`. - * `SSL_KEY` - Path to your ssl key file, so that ssl(https) can be enabled directly in node.js - * `SSL_CERT` - Path to your ssl cert file, so that ssl(https) can be enabled directly in node.js - * `SSL_CA` - Path to your ssl ca file, so that ssl(https) can be enabled directly in node.js + * `SSL_KEY` - Path to your ssl key file, so that ssl(https) can be enabled directly in node.js. If using Let's Encrypt, make this variable the path to your privkey.pem file (private key). + * `SSL_CERT` - Path to your ssl cert file, so that ssl(https) can be enabled directly in node.js. If using Let's Encrypt, make this variable the path to fullchain.pem file (cert + ca). + * `SSL_CA` - Path to your ssl ca file, so that ssl(https) can be enabled directly in node.js. If using Let's Encrypt, make this variable the path to chain.pem file (chain). * `HEARTBEAT` (`60`) - Number of seconds to wait in between database checks * `DEBUG_MINIFY` (`true`) - Debug option, setting to `false` will disable bundle minification to help tracking down error and speed up development - + * `DE_NORMALIZE_DATES`(`true`) - The Nightscout REST API normalizes all entered dates to UTC zone. Some Nightscout clients have broken date deserialization logic and expect to received back dates in zoned formats. Setting this variable to `true` causes the REST API to serialize dates sent to Nightscout in zoned format back to zoned format when served to clients over REST. ### Predefined values for your browser settings (optional) + * `TIME_FORMAT` (`12`)- possible values `12` or `24` * `NIGHT_MODE` (`off`) - possible values `on` or `off` * `SHOW_RAWBG` (`never`) - possible values `always`, `never` or `noise` - * `CUSTOM_TITLE` (`Nightscout`) - Usually name of T1 - * `THEME` (`default`) - possible values `default`, `colors`, or `colorblindfriendly` + * `CUSTOM_TITLE` (`Nightscout`) - Title for the main view + * `THEME` (`colors`) - possible values `default`, `colors`, or `colorblindfriendly` * `ALARM_TIMEAGO_WARN` (`on`) - possible values `on` or `off` * `ALARM_TIMEAGO_WARN_MINS` (`15`) - minutes since the last reading to trigger a warning * `ALARM_TIMEAGO_URGENT` (`on`) - possible values `on` or `off` @@ -258,19 +286,27 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm * `SHOW_PLUGINS` - enabled plugins that should have their visualizations shown, defaults to all enabled * `SHOW_FORECAST` (`ar2`) - plugin forecasts that should be shown by default, supports space delimited values such as `"ar2 openaps"` * `LANGUAGE` (`en`) - language of Nightscout. If not available english is used - * Currently supported language codes are: bg (Български), cs (Čeština), de (Deutsch), dk (Dansk), el (Ελληνικά), en (English), es (Español), fi (Suomi), fr (Français), he (עברית), hr (Hrvatski), it (Italiano), ko (한국어), nb (Norsk (Bokmål)), nl (Nederlands), pl (Polski), pt (Português (Brasil)), ro (Română), ru (Русский), sk (Slovenčina), sv (Svenska), zh_cn (中文(简体)), zh_tw (中文(繁體)) + * Currently supported language codes are: bg (Български), cs (Čeština), de (Deutsch), dk (Dansk), el (Ελληνικά), en (English), es (Español), fi (Suomi), fr (Français), he (עברית), hr (Hrvatski), it (Italiano), ko (한국어), nb (Norsk (Bokmål)), nl (Nederlands), pl (Polski), pt (Português (Brasil)), ro (Română), ru (Русский), sk (Slovenčina), sv (Svenska), tr (Turkish), zh_cn (中文(简体)), zh_tw (中文(繁體)) * `SCALE_Y` (`log`) - The type of scaling used for the Y axis of the charts system wide. * The default `log` (logarithmic) option will let you see more detail towards the lower range, while still showing the full CGM range. - * The `linear` option has equidistant tick marks, the range used is dynamic so that space at the top of chart isn't wasted. + * The `linear` option has equidistant tick marks; the range used is dynamic so that space at the top of chart isn't wasted. * The `log-dynamic` is similar to the default `log` options, but uses the same dynamic range and the `linear` scale. - * `EDIT_MODE` (`on`) - possible values `on` or `off`. Enable or disable icon allowing enter treatments edit mode + * `EDIT_MODE` (`on`) - possible values `on` or `off`. Enables the icon allowing for editing of treatments in the main view. + +### Predefined values for your server settings (optional) + * `INSECURE_USE_HTTP` (`false`) - Redirect unsafe http traffic to https. Possible values `false`, or `true`. Your site redirects to `https` by default. If you don't want that from Nightscout, but want to implement that with a Nginx or Apache proxy, set `INSECURE_USE_HTTP` to `true`. Note: This will allow (unsafe) http traffic to your Nightscout instance and is not recommended. + * `SECURE_HSTS_HEADER` (`true`) - Add HTTP Strict Transport Security (HSTS) header. Possible values `false`, or `true`. + * `SECURE_HSTS_HEADER_INCLUDESUBDOMAINS` (`false`) - includeSubdomains options for HSTS. Possible values `false`, or `true`. + * `SECURE_HSTS_HEADER_PRELOAD` (`false`) - ask for preload in browsers for HSTS. Possible values `false`, or `true`. + * `SECURE_CSP` (`false`) - Add Content Security Policy headers. Possible values `false`, or `true`. + * `SECURE_CSP_REPORT_ONLY` (`false`) - If set to `true` allows to experiment with policies by monitoring (but not enforcing) their effects. Possible values `false`, or `true`. ### Views - There are a few alternate web views available that display a simplified BG stream. Append any of these to your Nightscout URL: - * `/clock.html` - Shows current BG. Grey text on a black background. - * `/bgclock.html` - Shows current BG, trend arrow, and time of day. Grey text on a black background. - * `/clock-color.html` - Shows current BG and trend arrow. White text on a background that changes color to indicate current BG threshold (green = in range; blue = below range; yellow = above range; red = urgent below/above). + There are a few alternate web views available from the main menu that display a simplified BG stream. (If you launch one of these in a fullscreen view in iOS, you can use a left-to-right swipe gesture to exit the view.) + * `Clock` - Shows current BG, trend arrow, and time of day. Grey text on a black background. + * `Color` - Shows current BG and trend arrow. White text on a background that changes color to indicate current BG threshold (green = in range; blue = below range; yellow = above range; red = urgent below/above). Set `SHOW_CLOCK_DELTA` to `true` to show BG change in the last 5 minutes, set `SHOW_CLOCK_LAST_TIME` to `true` to always show BG age. + * `Simple` - Shows current BG. Grey text on a black background. ### Plugins @@ -280,7 +316,7 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm #### Default Plugins - These can be disabled by setting the `DISABLE` env var, for example `DISABLE="direction upbat"` + These can be disabled by adding them to the `DISABLE` variable, for example `DISABLE="direction upbat"` ##### `delta` (BG Delta) Calculates and displays the change between the last 2 BG values. @@ -302,7 +338,6 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm * `ALARM_TIMEAGO_URGENT` (`on`) - possible values `on` or `off` * `ALARM_TIMEAGO_URGENT_MINS` (`30`) - minutes since the last reading to trigger a urgent alarm - ##### `devicestatus` (Device Status) Used by `upbat` and other plugins to display device status info. Supports the `DEVICESTATUS_ADVANCED="true"` [extended setting](#extended-settings) to send all device statuses to the client for retrospective use and to support other plugins. @@ -339,7 +374,11 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm An option plugin to enable adding foods from database in Bolus Wizard and enable . ##### `rawbg` (Raw BG) - Calculates BG using sensor and calibration records from and displays an alternate BG values and noise levels. + Calculates BG using sensor and calibration records from and displays an alternate BG values and noise levels. Defaults that can be adjusted with [extended setting](#extended-settings) + * `DISPLAY` (`unsmoothed`) - Allows the user to control which algorithm is used to calculate the displayed raw BG values using the most recent calibration record. + * `unfiltered` - Raw BG is calculated by applying the calibration to the glucose record's unfiltered value. + * `filtered` - Raw BG is calculated by applying the calibration to the glucose record's filtered value. The glucose record's filtered values are generally produced by the CGM by a running average of the unfiltered values to produce a smoothed value when the sensor noise is high. + * `unsmoothed` - Raw BG is calculated by first finding the ratio of the calculated filtered value (the same value calculated by the `filtered` setting) to the reported glucose value. The displayed raw BG value is calculated by dividing the calculated unfiltered value (the same value calculated by the `unfiltered` setting) by the ratio. The effect is to exagerate changes in trend direction so the trend changes are more noticeable to the user. This is the legacy raw BG calculation algorithm. ##### `iob` (Insulin-on-Board) Adds the IOB pill visualization in the client and calculates values that used by other plugins. Uses treatments with insulin doses and the `dia` and `sens` fields from the [treatment profile](#treatment-profile). @@ -376,6 +415,14 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm * `IAGE_WARN` (`48`) - If time since last `Insulin Change` matches `IAGE_WARN`, user will be alarmed to to change the insulin reservoir * `IAGE_URGENT` (`72`) - If time since last `Insulin Change` matches `IAGE_URGENT`, user will be issued a persistent warning of overdue change. +##### `bage` (Battery Age) + Calculates the number of days and hours since the last `Pump Battery Change` treatment that was recorded. + * `BAGE_ENABLE_ALERTS` (`false`) - Set to `true` to enable notifications to remind you of upcoming pump battery change. + * `BAGE_DISPLAY` (`days`) - Set to `hours` to display time since last `Pump Battery Change` in hours only. + * `BAGE_INFO` (`312`) - If time since last `Pump Battery Change` matches `BAGE_INFO` hours, user will be warned of upcoming pump battery change (default of 312 hours is 13 days). + * `BAGE_WARN` (`336`) - If time since last `Pump Battery Change` matches `BAGE_WARN` hours, user will be alarmed to to change the pump battery (default of 336 hours is 14 days). + * `BAGE_URGENT` (`360`) - If time since last `Pump Battery Change` matches `BAGE_URGENT` hours, user will be issued a persistent warning of overdue change (default of 360 hours is 15 days). + ##### `treatmentnotify` (Treatment Notifications) Generates notifications when a treatment has been entered and snoozes alarms minutes after a treatment. Default snooze is 10 minutes, and can be set using the `TREATMENTNOTIFY_SNOOZE_MINS` [extended setting](#extended-settings). @@ -388,7 +435,7 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm * `BRIDGE_USER_NAME` - Your user name for the Share service. * `BRIDGE_PASSWORD` - Your password for the Share service. * `BRIDGE_INTERVAL` (`150000` *2.5 minutes*) - The time to wait between each update. - * `BRIDGE_MAX_COUNT` (`1`) - The maximum number of records to fetch per update. + * `BRIDGE_MAX_COUNT` (`1`) - The number of records to attempt to fetch per update. * `BRIDGE_FIRST_FETCH_COUNT` (`3`) - Changes max count during the very first update only. * `BRIDGE_MAX_FAILURES` (`3`) - How many failures before giving up. * `BRIDGE_MINUTES` (`1400`) - The time window to search for new data per update (default is one day in minutes). @@ -402,6 +449,7 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm * `MMCONNECT_SGV_LIMIT` (`24`) - Maximum number of recent sensor glucose values to send to Nightscout on each request. * `MMCONNECT_VERBOSE` - Set this to "true" to log CareLink request information to the console. * `MMCONNECT_STORE_RAW_DATA` - Set this to "true" to store raw data returned from CareLink as `type: "carelink_raw"` database entries (useful for development). + * `MMCONNECT_SERVER` - Set this to `EU` if you're using the European Medtronic services ##### `pump` (Pump Monitoring) Generic Pump Monitoring for OpenAPS, MiniMed Connect, RileyLink, t:slim, with more on the way @@ -427,6 +475,12 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm * `OPENAPS_URGENT` (`60`) - The number of minutes since the last loop that needs to be exceed before an urgent alarm is triggered * `OPENAPS_FIELDS` (`status-symbol status-label iob meal-assist rssi`) - The fields to display by default. Any of the following fields: `status-symbol`, `status-label`, `iob`, `meal-assist`, `freq`, and `rssi` * `OPENAPS_RETRO_FIELDS` (`status-symbol status-label iob meal-assist rssi`) - The fields to display in retro mode. Any of the above fields. + * `OPENAPS_PRED_IOB_COLOR` (`#1e88e5`) - The color to use for IOB prediction lines. Colors can be in `#RRGGBB` format, but [other CSS color units](https://www.w3.org/TR/css-color-3/#colorunits) may be used as well. + * `OPENAPS_PRED_COB_COLOR` (`#FB8C00`) - The color to use for COB prediction lines. Same format as above. + * `OPENAPS_PRED_ACOB_COLOR` (`#FB8C00`) - The color to use for ACOB prediction lines. Same format as above. + * `OPENAPS_PRED_ZT_COLOR` (`#00d2d2`) - The color to use for ZT prediction lines. Same format as above. + * `OPENAPS_PRED_UAM_COLOR` (`#c9bd60`) - The color to use for UAM prediction lines. Same format as above. + * `OPENAPS_COLOR_PREDICTION_LINES` (`true`) - Enables / disables the colored lines vs the classic purple color. Also see [Pushover](#pushover) and [IFTTT Maker](#ifttt-maker). @@ -438,15 +492,28 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm * `LOOP_URGENT` (`60`) - The number of minutes since the last loop that needs to be exceeded before an urgent alarm is triggered * Add `loop` to `SHOW_FORECAST` to show forecasted BG. -##### `xdrip-js` (xDrip-js) +For remote overrides, the following extended settings must be configured: + * `LOOP_APNS_KEY` - Apple Push Notifications service (APNs) Key, created in the Apple Developer website. + * `LOOP_APNS_KEY_ID` - The Key ID for the above key. + * `LOOP_DEVELOPER_TEAM_ID` - Your Apple developer team ID. + * `LOOP_PUSH_SERVER_ENVIRONMENT` - (optional) Set this to `production` if you are using a provisioning profile that specifies production aps-environment, such as when distributing builds via TestFlight. + +##### `override` (Override Mode) + Additional monitoring for DIY automated insulin delivery systems to display real-time overrides such as Eating Soon or Exercise Mode: + * Requires `DEVICESTATUS_ADVANCED="true"` to be set + +##### `xdripjs` (xDrip-js) Integrated xDrip-js monitoring, uses these extended settings: * Requires `DEVICESTATUS_ADVANCED="true"` to be set - * `XDRIP-JS_ENABLE_ALERTS` (`false`) - Set to `true` to enable notifications when CGM state is not OK or battery voltages fall below threshold. - * `XDRIP-JS_STATE_NOTIFY_INTRVL` (`0.5`) - Set to number of hours between CGM state notifications - * `XDRIP-JS_WARN_BAT_V` (`300`) - The voltage of either transmitter battery, a warning will be triggered when dropping below this threshold. + * `XDRIPJS_ENABLE_ALERTS` (`false`) - Set to `true` to enable notifications when CGM state is not OK or battery voltages fall below threshold. + * `XDRIPJS_STATE_NOTIFY_INTRVL` (`0.5`) - Set to number of hours between CGM state notifications + * `XDRIPJS_WARN_BAT_V` (`300`) - The voltage of either transmitter battery, a warning will be triggered when dropping below this threshold. ##### `alexa` (Amazon Alexa) - Integration with Amazon Alexa, [detailed setup instructions](lib/plugins/alexa-plugin.md) + Integration with Amazon Alexa, [detailed setup instructions](docs/plugins/alexa-plugin.md) + +##### `googlehome` (Google Home/DialogFLow) + Integration with Google Home (via DialogFlow), [detailed setup instructions](docs/plugins/googlehome-plugin.md) ##### `speech` (Speech) Speech synthesis plugin. When enabled, speaks out the blood glucose values, IOB and alarms. Note you have to set the LANGUAGE setting on the server to get all translated alarms. @@ -459,7 +526,7 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm Some plugins support additional configuration using extra environment variables. These are prefixed with the name of the plugin and a `_`. For example setting `MYPLUGIN_EXAMPLE_VALUE=1234` would make `extendedSettings.exampleValue` available to the `MYPLUGIN` plugin. Plugins only have access to their own extended settings, all the extended settings of client plugins will be sent to the browser. - + * `DEVICESTATUS_ADVANCED` (`true`) - Defaults to true. Users who only have a single device uploading data to Nightscout can set this to false to reduce the data use of the site. #### Pushover @@ -490,19 +557,18 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm For testing/development try [localtunnel](http://localtunnel.me/). #### IFTTT Maker - In addition to the normal web based alarms, and pushover, there is also integration for [IFTTT Maker](https://ifttt.com/maker). + In addition to the normal web based alarms, and pushover, there is also integration for [IFTTT Webhooks](https://ifttt.com/maker_webhooks). - With Maker you are able to integrate with all the other [IFTTT Channels](https://ifttt.com/channels). For example you can send a tweet when there is an alarm, change the color of hue light, send an email, send and sms, and so much more. + With Maker you are able to integrate with all the other [IFTTT Services](https://ifttt.com/services). For example you can send a tweet when there is an alarm, change the color of hue light, send an email, send and sms, and so much more. 1. Setup IFTTT account: [login](https://ifttt.com/login) or [create an account](https://ifttt.com/join) - 2. Find your secret key on the [maker page](https://ifttt.com/maker) - 3. Configure Nightscout by setting these environment variables: - * `ENABLE` - `maker` should be added to the list of plugin, for example: `ENABLE="maker"`. - * `MAKER_KEY` - Set this to your secret key that you located in step 2, for example: `MAKER_KEY="abcMyExampleabc123defjt1DeNSiftttmak-XQb69p"` This also support a space delimited list of keys. - * `MAKER_ANNOUNCEMENT_KEY` - An optional Maker key, will be used for system wide user generated announcements. If not defined this will fallback to `MAKER_KEY`. A possible use for this is sending important messages and alarms to a CWD that you don't want to send all notification too. This also support a space delimited list of keys. - 4. [Create a recipe](https://ifttt.com/myrecipes/personal/new) or see [more detailed instructions](lib/plugins/maker-setup.md#create-a-recipe) - - Plugins can create custom events, but all events sent to maker will be prefixed with `ns-`. The core events are: + 2. Follow the [Detailed IFTTT setup Instructions](docs/plugins/maker-setup.md) + 3. Configure Nightscout by setting these webpage environment variables: + * `ENABLE` - `maker` should be added to the list of plugins, for example: `ENABLE="maker"`. + * `MAKER_KEY` - Set this to your secret key (see [[Detailed Instructions](docs/plugins/maker-setup.md) ) `MAKER_KEY="abcMyExampleabc123defjt1DeNSiftttmak-XQb69p"` This also supports a space delimited list of keys. + * `MAKER_ANNOUNCEMENT_KEY` - An optional Maker key, will be used for system wide user generated announcements. If not defined this will fallback to `MAKER_KEY`. A possible use for this is sending important messages and alarms to another device that you don't want to send all notification too. This also support a space delimited list of keys. + + Plugins can create custom events, but all events sent to IFTTT webhooks will be prefixed with `ns-`. The core events are: * `ns-event` - This event is sent to the maker service for all alarms and notifications. This is good catch all event for general logging. * `ns-allclear` - This event is sent to the maker service when an alarm has been ack'd or when the server starts up without triggering any alarms. For example, you could use this event to turn a light to green. * `ns-info` - Plugins that generate notifications at the info level will cause this event to also be triggered. It will be sent in addition to `ns-event`. @@ -568,6 +634,12 @@ Feel free to [post an issue][issues], but read the [wiki][wiki] first. [issues]: https://github.com/nightscout/cgm-remote-monitor/issues [wiki]: https://github.com/nightscout/cgm-remote-monitor/wiki +### Browser testing suite provided by +[![BrowserStack][browserstack-img]][browserstack-url] + +[browserstack-img]: /static/images/browserstack-logo.png +[browserstack-url]: https://www.browserstack.com/ + License --------------- diff --git a/app.js b/app.js index 5fd5f85f254..7c6f67b1ee1 100644 --- a/app.js +++ b/app.js @@ -1,211 +1,321 @@ 'use strict'; -var _get = require('lodash/get'); -var express = require('express'); -var compression = require('compression'); -var bodyParser = require('body-parser'); -var prettyjson = require('prettyjson'); - -var path = require('path'); -var fs = require('fs'); - -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. - - app.set('view engine', 'ejs'); - // this allows you to render .html files as templates in addition to .ejs - app.engine('html', require('ejs').renderFile); - app.engine('appcache', require('ejs').renderFile); - app.set("views", path.join(__dirname, "views/")); - - app.locals.cachebuster = fs.readFileSync(process.cwd() + '/tmp/cacheBusterToken').toString().trim(); - - if (ctx.bootErrors && ctx.bootErrors.length > 0) { - app.get('*', require('./lib/server/booterror')(ctx)); - return app; +const _get = require('lodash/get'); +const express = require('express'); +const compression = require('compression'); +const bodyParser = require('body-parser'); + +const path = require('path'); +const fs = require('fs'); + +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. + var insecureUseHttp = env.insecureUseHttp; + var secureHstsHeader = env.secureHstsHeader; + if (!insecureUseHttp) { + console.info('Redirecting http traffic to https because INSECURE_USE_HTTP=', insecureUseHttp); + app.use((req, res, next) => { + if (req.header('x-forwarded-proto') === 'https' || req.secure) { + next(); + } else { + res.redirect(307, `https://${req.header('host')}${req.url}`); + } + }); + if (secureHstsHeader) { // Add HSTS (HTTP Strict Transport Security) header + console.info('Enabled SECURE_HSTS_HEADER (HTTP Strict Transport Security)'); + const helmet = require('helmet'); + var includeSubDomainsValue = env.secureHstsHeaderIncludeSubdomains; + var preloadValue = env.secureHstsHeaderPreload; + app.use(helmet({ + hsts: { + maxAge: 31536000 + , includeSubDomains: includeSubDomainsValue + , preload: preloadValue + } + , frameguard: false + })); + if (env.secureCsp) { + var secureCspReportOnly = env.secureCspReportOnly; + if (secureCspReportOnly) { + console.info('Enabled SECURE_CSP (Content Security Policy header). Not enforcing. Report only.'); + } else { + console.info('Enabled SECURE_CSP (Content Security Policy header). Enforcing.'); + } + app.use(helmet.contentSecurityPolicy({ //TODO make NS work without 'unsafe-inline' + directives: { + defaultSrc: ["'self'"] + , styleSrc: ["'self'", 'https://fonts.googleapis.com/', "'unsafe-inline'"] + , scriptSrc: ["'self'", "'unsafe-inline'"] + , fontSrc: ["'self'", 'https://fonts.gstatic.com/', 'data:'] + , imgSrc: ["'self'", 'data:'] + , objectSrc: ["'none'"], // Restricts
- -diff --git a/views/bgclock.html b/views/bgclock.html deleted file mode 100644 index 903a395d56a..00000000000 --- a/views/bgclock.html +++ /dev/null @@ -1,142 +0,0 @@ - - -
- - - -
- - - - - - - - - - - - - - - -
-