1.0.1 • Published 8 years ago

mapi-server v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
8 years ago

Magic API Server

Installation

npm i -g mapi-server

Setup

Create a configuration file config.json with the following options:

  • port: Server port
  • prefix: base path of all routes
  • plugins: mapi-server plugins to use and their configuration (see Plugins section)

Example:

{
  "port": 3001,
  "prefix": "/api",
  "plugins": [
    { "type": "nedb", "autoCompactionInterval": 600000, "filename": "data/db" },
    { "type": "body-parser" },
    { "type": "cors" },
    { "type": "auth", "secret": "869B16E62AC601837DF4AA508E74628CD20B28A2" },
    { "type": "ws" },
    { "type": "log", "format": "dev" }
  ]
}

Plugins

nedb

Install an nedb Database under server.db and req.db.

Options:

  • autoCompactionInterval: inteval in ms to trigger nedb auto-compaction
  • filename: path to the database file

mail

Install nodemailer as server.sendmail and req.sendmail.

Options:

auth

Install Authentication middleware und server.auth and add req.user.

Options:

  • secret: a random string used to encode passwords
  • requireVerification: must the account be verified before it is used?
  • verification.subject: subject line for the verification email
  • verification.text: plain text for the verification email
  • verification.html: html text for the verification email

session

Install an Express session.

Stores:

Configure a store via the store option with the following options:

  • type: nedb or file
  • other options are passed to the store

body-parser

Install the Express body-parser and parse JSON and URL-encoded body data.

cors

Install Express cors for all routes.

log

Install a Morgan logger.

Options:

  • format: log format

ws

Enable websocket routes