OpenBikeSensor Web API
Find a file
2020-11-19 17:48:45 +01:00
_helpers feat: add registration flow with email verification 2020-10-22 23:53:43 +02:00
_middleware feat: add registration flow with email verification 2020-10-22 23:53:43 +02:00
accounts feat: add registration flow with email verification 2020-10-22 23:53:43 +02:00
config configurable mailserver and sender 2020-10-23 00:41:16 +02:00
logic fix: when detecting format, first apply the dollar->newline hack 2020-11-19 17:48:45 +01:00
models feat: generate TrackData points when saving tracks through PUT, and return raw body through GET /:track 2020-11-18 22:17:00 +01:00
postman-examples chore: update package versions and readme 2020-10-01 13:40:11 +02:00
public first version of the OpenBikeSensor Web API 2020-04-13 02:02:40 +02:00
routes refactor: switch to async/await syntax in track routes 2020-11-18 23:00:08 +01:00
.gitignore chore: remove yarn.lock, because package-lock.json exists and the two would not stay up to date with each other anyway 2020-11-17 18:30:36 +01:00
app.js fix: allow big uploads (up to 50mb) 2020-11-18 21:50:33 +01:00
docker-compose.yaml chore: fix dev setup 2020-11-18 17:24:15 +01:00
Dockerfile chore: add docker-compose support and Dockerfile for building the app image 2020-11-17 18:30:36 +01:00
LICENSE Initial commit 2020-04-13 01:52:25 +02:00
package-lock.json wip 2020-11-18 20:53:35 +01:00
package.json refactor: switch to async/await syntax in track routes 2020-11-18 23:00:08 +01:00
README.md chore: update README to reflect docker startup process, also: formatting 2020-11-17 18:30:36 +01:00

OpenBikeSensor Web API

The backend API for the OpenBikeSensor Web App.

Direct setup

Requirements

  • A working installation of npm and node.js - get the latest node.js LTS release at the node.js homepage and verify it's working via node -v and npm -v in a command prompt of your choice. At least node version 10.x is required.
  • A working installation of Docker for the containerized MongoDB. Alternatively, you can set up your own MongoDB elsewhere.

First start

To get started you first need to download all dependencies in the project's root folder:

npm install

Next up we have to run a MongoDB instance. The following command uses docker, it assumes you have the docker daemon installed and running. Working with docker might require root privileges, depending on your docker setup, so you might want to prefix the following command with sudo:

npm run mongo:start

The development server will be accessible at http://localhost:3000/api after starting it like this:

npm run dev

To stop the database when you're done developing, run (potentially with sudo):

npm run mongo:stop

Docker setup

If you have docker and don't want to bother installing Node.js on your machine, you can run the application inside docker as well:

docker-compose up -d

This will first build the obs-api image, which contains all the steps outlined above, and then run the services, both a mongodb and the api itself, in docker containers. Interaction with the processes is different though, expect other guides or commands to work differently in this type of setup.

Custom MongoDB installation

If you have your own MongoDB instance running somewhere, you can set the environment variable MONGODB_URL when starting the server, and it will read that URL for connecting.

export MONGODB_URL=mongodb://user:password@mongodb.example.com/obs-app-database

This does not work when using docker-compose, in that case, you will have to modify the docker-compose.yaml to include that URL.

Usage

Uploading a track for test purposes

Uploading a track to the local server requires multiple steps, as uploading is not possible via the dummy upload form in the corresponding web app yet:

  • Create a user in the web app and copy the user id, which can be found at (http://localhost:4200/settings) as "API key"
  • Import the Postman script "add-track.json" from the "postman-examples" into Postman
  • In each of the three requests add your user id in the "Pre-request script" tab as the value for the "UserId" variable
  • As tracks have to be split into smaller parts to get a working upload from the sensor you have to run the three requests in the order of: begin -> add -> end
  • View your freshly uploaded track at (http://localhost:4200) -> Home -> Your feed

Sending E-Mails

By default in development mode mails are not sent, but instead the mail data is logged to the console. This can be overriden with the --devSendMails flag if you start the application like so: npm run dev -- --devSendMails.

Mails are also always sent in production mode!

For actually sending e-mails the mailserver, sender, user and password for the SMTP server need to be specified as environment variables:

  • MAILUSER -- the smtp mailbox login name
  • MAILPW -- password for the mailbox
  • MAILSERVER -- the hostname of the SMTP server, e.g. mail.example.com
  • MAILSENDER -- sender name, e.g. noreply@example.com

Full command example:

MAILSERVER=mail.example.com MAILSENDER=noreply@example.com MAILUSER=my_mail_login

MAILPW=hunter2 npm run dev -- --devSendMails