Skip to content

Commit 58bee26

Browse files
Merge branch 'split-packages' into development
2 parents f6b1257 + f22fc28 commit 58bee26

File tree

116 files changed

+916
-5320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+916
-5320
lines changed

Diff for: .dockerignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
node_modules
2-
mongo-data
32
userimages
4-
osem-mongo
53
docker-compose.yml
64
Dockerfile
75
.env*

Diff for: .eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ module.exports = {
152152
'error',
153153
'never'
154154
],
155-
'no-warning-comments': 'error'
155+
'no-warning-comments': 'error',
156+
'prefer-promise-reject-errors': 'error'
156157
}
157158
};

Diff for: .gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ dump
1616
npm-debug.log
1717
node_modules
1818

19-
config/index.js
20-
2119
userimages
22-
mongo-data
2320
.env
2421
doc/
2522
revision
23+
24+
dev_run_migration.sh

Diff for: utils/deploy-docs.sh renamed to .scripts/deploy-docs.sh

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
set -euo pipefail
44
IFS=$'\n\t'
55

6-
76
# move to the build dir..
8-
cd $TRAVIS_BUILD_DIR
7+
cd "$TRAVIS_BUILD_DIR"
98

109
# install apidocs
11-
npm install -g [email protected]
12-
13-
# deploy!
10+
npm install -g [email protected]
1411

1512
# run apidoc
1613
apidoc -i . -f js -e node_modules
@@ -42,6 +39,5 @@ git config user.email "[email protected]"
4239
# commit
4340
git commit -m "apidoc build from ${TRAVIS_COMMIT} by Travis"
4441

45-
# push to github!
42+
# push to github
4643
git push "https://${GITHUB_TOKEN}@github.com/${GITHUB_REPO}.git" gh-pages
47-

Diff for: .scripts/npm_tag-container.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
IFS=$'\n\t'
5+
6+
currentBranch=$(git branch | grep -e "^*" | cut -d' ' -f 2)
7+
8+
if [ "$currentBranch" != "master" ]; then
9+
echo "Tags for containers can only be made from 'master' branch"
10+
exit 1
11+
fi
12+
13+
# Extract latest git tag
14+
currentVersion=$(git tag -l --sort=-v:refname | head -n 1 | tr -d 'v')
15+
16+
# Increment
17+
newVersion=$(($currentVersion+1))
18+
19+
tagName="v$newVersion"
20+
21+
# tag new version
22+
git tag "$tagName"
23+
24+
echo "Creation of new tag for docker hub was successful. New tag is '$tagName'."
25+
echo "Please run 'git push origin master' to trigger the build on docker hub."

Diff for: .travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ node_js:
55
- "6"
66

77
install: true
8-
script: ./utils/deploy-docs.sh
8+
script: ./api/.scripts/deploy-docs.sh
99

1010
env:
1111
global:

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# openSenseMap API Changelog
2+
3+
## Unreleased
4+
- Initial Release after splitting api and models

Diff for: Dockerfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ COPY yarn.lock /usr/src/app/
99

1010
# npm rebuild is required because the prebuilt binaries are not compatible with musl
1111
# remove when https://github.com/kelektiv/node.bcrypt.js/issues/528 is resolved
12-
RUN yarn install --pure-lockfile \
13-
&& apk --no-cache --virtual .build add build-base python \
14-
&& npm rebuild bcrypt --build-from-source \
15-
&& apk del .build
12+
RUN yarn install --pure-lockfile --production \
13+
&& apk --no-cache --virtual .build add build-base python \
14+
&& npm rebuild bcrypt --build-from-source \
15+
&& apk del .build
1616
COPY . /usr/src/app
1717

1818
# for git 2.1.4
@@ -21,4 +21,4 @@ RUN apk --no-cache --virtual .git add git \
2121
&& rm -rf .git \
2222
&& apk del .git
2323

24-
CMD [ "npm", "start" ]
24+
CMD [ "yarn", "start" ]

Diff for: README.md

+61-48
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,85 @@
1-
openSenseMap-API
2-
================
1+
![openSenseMap API](https://raw.githubusercontent.com/sensebox/resources/master/images/openSenseMap_API_github.png)
32

4-
[![Join the chat at https://gitter.im/sensebox/openSenseMap-API](https://badges.gitter.im/sensebox/openSenseMap-API.svg)](https://gitter.im/sensebox/openSenseMap-API?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5-
This is the back-end for [openSenseMap](https://opensensemap.org).
3+
[![sensebox/openSenseMap-API Build Status](https://travis-ci.org/sensebox/openSenseMap-API.svg?branch=master)](https://travis-ci.org/sensebox/openSenseMap-API)
64

7-
openSenseMap is part of the [senseBox](https://sensebox.de) project.
8-
To get more information about openSenseMap and senseBox visit the before mentioned links or have a look at this [video](https://www.youtube.com/watch?v=uTOWYa42_rI).
5+
This repository contains the Node.js package [@sensebox/opensensemap-api](https://www.npmjs.com/package/@sensebox/opensensemap-api), which is the HTTP REST API used by [https://opensensemap.org](https://opensensemap.org) running at [https://api.opensensemap.org](https://api.opensensemap.org). To get more information about openSenseMap and senseBox visit the before mentioned links or have a look at this [video](https://www.youtube.com/watch?v=uTOWYa42_rI), read the [API docs](https://docs.opensensemap.org) or the [openSenseMap](https://osem.books.sensebox.de/) chapter in our [books](https://books.sensebox.de/). openSenseMap is part of the [senseBox] project.
96

10-
Originally, this API has been built as part the bachelor thesis of @mpfeil at the ifgi (Institute for Geoinformatics, WWU Münster).
7+
Originally, this API has been built as part of the bachelor thesis of [@mpfeil](https://github.com/mpfeil) at the ifgi (Institute for Geoinformatics, WWU Münster) and is currently maintained by [@ubergesundheit](https://github.com/ubergesundheit).
118

12-
### Technologies
9+
## Configuration
10+
Configuration values reside in the `lib/config.js` file. Configuration can also be set through environment variables starting with `OSEM_`. Environment variables override values in `lib/config.js`.
1311

14-
* [node.js]
15-
* [MongoDB]
16-
17-
### Development
12+
## Development
13+
- Have [Node.js] v6, [yarn](https://yarnpkg.com/), [Docker](https://docs.docker.com/engine/installation/) and [docker-compose](https://docs.docker.com/compose/install/) installed
14+
- Start your development database (`docker-compose up -d db`)
15+
- Check out `development` branch (`git checkout development`)
16+
- Run `yarn install`
17+
- Create your own branch `git checkout -b my-awesome-branch`
18+
- Commit your changes to your branch and push it to your fork
19+
- Create a pull request against the `development` branch
1820

19-
#### Node.js
20-
It is assumed that you have installed node.js Version 6 LTS. Install dependencies with [yarn](https://yarnpkg.com/)
21+
## Running Tests
22+
You can run the tests in containers using Docker and docker-compose.
2123
```
24+
# Run this the first time or every time you change dependencies in package.json
2225
yarn install
23-
```
24-
25-
There are several config keys in `config/index.js`. These can also be configured through environment keys. Just prefix your environment keys with `OSEM_` to be read by the api.
26+
./run-tests.sh build
2627
27-
#### Database
28-
The API needs a running MongoDB instance with a `OSeM-api` database and credentials.
29-
30-
The best way to run the database for development is to use the supplied `docker-compose.yml` and run
31-
```
32-
docker-compose up -d db
28+
./run-tests.sh
3329
```
3430

35-
### `require()` openSenseMap-API for other projects
31+
## Related projects
3632

37-
You can require several parts of the API in other projects.
33+
### Services
34+
- [openSenseMap Frontend](https://github.com/sensebox/openSenseMap)
35+
- [ttn-osem-integration](https://github.com/sensebox/ttn-osem-integration)
36+
- [openSenseMap-MQTT-client](https://github.com/sensebox/openSenseMap-MQTT-client)
37+
- [sensebox-mailer](https://github.com/sensebox/sensebox-mailer)
3838

39-
Install it as dependency
40-
```
41-
# for specific branch/commit/tag append #<branch/commit/tag>
42-
yarn add git://github.com/sensebox/openSenseMap-API.git
43-
```
39+
### Libraries
40+
- [sketch-templater](https://github.com/sensebox/node-sketch-templater)
41+
- [openSenseMap-API-models](https://github.com/sensebox/openSenseMap-API-models)
4442

45-
This allows you to use parts like models and decoding in your own project. See `index.js`.
43+
### Deployment
44+
- [OSeM-compose](https://github.com/sensebox/OSeM-compose)
45+
- [openSenseMap-infrastructure](https://github.com/sensebox/openSenseMap-infrastructure)
4646

47-
### Create the JSDoc pages
47+
## Technologies
4848

49-
To create the documentation you need [apidocjs](http://apidocjs.com/) and run:
50-
```
51-
apidoc -e node_modules/
52-
```
49+
* [Node.js]
50+
* [MongoDB]
5351

54-
### Running Tests
55-
You can run the tests in containers using docker and docker-compose.
56-
```
57-
# Only run this once or every time you change dependencies in package.json
58-
docker-compose -p osemapitest -f tests-docker-compose.yml build osem-api
52+
## Organization
5953

60-
./run-tests.sh
61-
```
54+
### Branches
55+
- master (runs in production)
56+
- Is used for container build tags
57+
- development (runs on testing server)
58+
- Bleeding edge and possibly unstable development version
59+
- gh-pages
60+
- Hosts API docs for [https://docs.opensensemap.org/](https://docs.opensensemap.org/)
61+
- Is generated and pushed to github by Travis CI
62+
63+
### Tags and Versions
64+
Git Tags are used for Docker hub builds (like `v1`). Version number is increased by one for each new version. Docker images are built automatically by the Docker hub for all tags starting with `v`
6265

63-
### Running in Production
66+
#### Development container images
67+
Every commit on branch `development` will be built with the tag `development`.
6468

65-
Look at the [OSeM-compose](https://github.com/sensebox/osem-compose) repository. It contains a deployment with docker compose.
69+
#### Versioned container images
70+
- Check out `master` branch
71+
- Go to root directory
72+
- Run tests
73+
- Optional: Build docker image locally
74+
- Commit everything needed for the container image
75+
- Run `npm run tag-container`
76+
- Run `git push origin master`
6677

67-
### License
78+
## License
6879

69-
[MIT](license.md) - Matthias Pfeil 2015 - 2017
80+
[MIT](license.md) - Matthias Pfeil 2015 - now
7081

71-
[node.js]:http://nodejs.org/
82+
[Node.js]:http://nodejs.org/
7283
[MongoDB]:http://www.mongodb.com/
84+
[openSenseMap]:https://opensensemap.org/
85+
[senseBox]:https://sensebox.de/

Diff for: app.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33
* Booya!
44
*/
55

6+
/**
7+
* define for Datetype parameters
8+
* @apiDefine ISO8601Date A ISO8601 formatted timestamp. Will be parsed by MomentJS with enabled strict mode
9+
*/
10+
611
'use strict';
712

813
const restify = require('restify'),
914
{ fullResponse, queryParser, jsonBodyParser, pre: { sanitizePath } } = restify.plugins,
10-
utils = require('./lib/utils'),
11-
db = require('./lib/db'),
12-
{ preRequest, preCors } = require('./lib/helpers/apiUtils'),
13-
Box = require('./lib/models').Box,
15+
config = require('./lib/config'),
16+
{ preRequest, preCors, Honeybadger, softwareRevision, postToSlack } = require('./lib/helpers/apiUtils'),
1417
routes = require('./lib/routes'),
1518
passport = require('passport'),
16-
log = require('./lib/log');
17-
18-
const { config, Honeybadger } = utils;
19+
log = require('./lib/log'),
20+
{ db } = require('@sensebox/opensensemap-api-models');
1921

2022
const server = restify.createServer({
21-
name: `opensensemap-api (${utils.softwareRevision})`,
23+
name: `opensensemap-api (${softwareRevision})`,
2224
log: log
2325
});
2426

@@ -45,8 +47,7 @@ db.connect()
4547
.then(function () {
4648
server.listen(config.port, function () {
4749
log.info(`${server.name} listening at ${server.url}`);
48-
utils.postToSlack(`openSenseMap API started. Revision: ${utils.softwareRevision}`);
49-
Box.connectMQTTBoxes();
50+
postToSlack(`openSenseMap API started. Revision: ${softwareRevision}`);
5051
});
5152
})
5253
.catch(function (err) {

Diff for: index.js

-13
This file was deleted.

Diff for: config/index.js renamed to lib/config.js

-28
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const isProdEnv = function isProdEnv () {
88
// environment variables starting with `OSEM_` will override the values here.
99
// Example: `OSEM_targetfolder` will override the setting for `targetFolder`
1010
const config = {
11-
imageFolder: './userimages/', // absolute location of user images
1211
logFolder: './logs/', // absolute location of error log files
1312

1413
// database configuration, will be concatenated to a mongo db connection string
@@ -22,7 +21,6 @@ const config = {
2221
api_base_domain: 'localhost', // the naked api domain. For example api.opensensemap.org
2322
api_protocol: (isProdEnv() ? 'https' : 'http'),
2423
api_url: '', // generated if not set from api_protocol and api_base_domain
25-
api_measurements_post_domain: '', //just the naked ingress domain. For example ingress.opensensemap.org
2624

2725
port: 8000, // port the api will bind to
2826

@@ -31,39 +29,20 @@ const config = {
3129
userPath: '/users', // user methods
3230
statisticsPath: '/statistics', //statistics methods
3331

34-
mailer_url: '', // leave empty to not send emails. For example: https://mailer:3924/
35-
mailer_cert: '',
36-
mailer_key: '',
37-
mailer_ca: '',
38-
mailer_origin: '', // set to the address where your frontend runs. for example: https://opensensemap.org
39-
4032
slack_url: '', // for slack integration
4133

4234
honeybadger_apikey: '',
4335

44-
// TODO: add config key to osem-compose
4536
jwt_secret: 'OH GOD THIS IS SO INSECURE PLS CHANGE ME', // should be at least 32 characters
4637
jwt_algorithm: 'HS256',
47-
jwt_validity_ms: 3600000, // 1 hour
4838
jwt_issuer: '', // usually the base url of the api. generated if not set from api_protocol and api_base_domain. for example https://api.opensensemap.org
4939

50-
refresh_token_secret: 'I ALSO WANT TO BE CHANGED',
51-
refresh_token_algorithm: 'sha256',
52-
refresh_token_validity_ms: 604800000, // 1 week
53-
54-
password_min_length: 8,
55-
password_salt_factor: (isProdEnv() ? 13 : 1), // use at least 10, max 31 (because the lib only allows this much. maybe switch later)
56-
5740
isProdEnv
5841
};
5942

60-
let env_has_dbconnectionstring = false;
6143
for (const envKey in process.env) {
6244
if (envKey.indexOf('OSEM_') === 0) {
6345
const configKey = envKey.substring(5);
64-
if (env_has_dbconnectionstring === false && configKey === 'dbconnectionstring') {
65-
env_has_dbconnectionstring = true;
66-
}
6746
if (config[configKey] && typeof config[configKey] === 'number') {
6847
config[configKey] = parseInt(process.env[envKey], 10);
6948
} else {
@@ -72,17 +51,10 @@ for (const envKey in process.env) {
7251
}
7352
}
7453

75-
if (env_has_dbconnectionstring === false) {
76-
config.dbconnectionstring = `mongodb://${config.dbuser}:${config.dbuserpass}@${config.dbhost}:${config.dbport}/${config.dbdb}?authSource=${config.dbauthsource}`;
77-
}
78-
7954
// set composite config keys
8055
if (config.api_url === '') {
8156
config.api_url = `${config.api_protocol}://${config.api_base_domain}`;
8257
}
83-
if (config.jwt_issuer === '') {
84-
config.jwt_issuer = `${config.api_protocol}://${config.api_base_domain}`;
85-
}
8658

8759
// freeze config
8860
module.exports = Object.freeze(config);

0 commit comments

Comments
 (0)