/leerstandsmelder-node-api

Leerstandsmelder Node.js API server

Primary LanguageJavaScriptMIT LicenseMIT

Leerstandsmelder API

Codacy Badge Build Status dependency Status devDependency Status bitHound Code

API server for Leerstandsmelder.de based on restify and written in ES6 JavaScript for Node.js.

This software is part of a complete relaunch of the platform, now making it open source and independent from Google's map service. The API has a pretty standard JSON-over-HTTP CRUD interface and adds an interface to basic geospatial queries through the 2D-index in MongoDB.

You can find the accompanying frontend and API client in the Leerstandsmelder GitHub repositories.

Requirements

  • NodeJS 6.x or 8.x
  • MongoDB 3.x
  • Redis 3.x

Setup

Install dependencies with npm install, copy config.default.json to config.json. You can then create an admin user by running ./bin/setup.js.

Running

Start the server with

node app.js

Management scripts

./bin/add-user-scope.js --email=user@host.com --scope=SCOPE_TO_SET adds the specified scope (e.g. admin, editor or a region admin with region-REGION_UUID) to the API Key associated with the supplied email address.

./bin/backup.sh /path/to/dir/ dumps the DB to the specified location (do not omit the trailing slash)

./bin/rebuild-acls.js purges and rebuilds all ACLs (caution: maybe make a backup before running this...)

Redirecting legacy URLs

There is a bundled redirect-server which can be mapped to legacy-style URLs and redirect them accordingly. Set it up in config.json and start it with

node ./legacy-redirect.js

Then map it with a regular expression as shown in this example for Nginx:

location ~* ^/[a-z,0-9,-]+/places/[a-z,0-9,-]+$ {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass http://localhost:7070;
    proxy_redirect off;
    proxy_buffering off;
}

Documentation

The API is documented using Swagger and is served at /api-docs at the respective API host. You can start a webserver to view the documentation by running

gulp swagger

Development

The project uses ES6 JavaScript and you are encouraged to lint the code using JSHint before pushing it or creating a pull request.

Testing

Uses Mocha and Chai. Run tests with npm test (tests are far from complete).