Skip to content

matter-in-motion/transports.http

Repository files navigation

Matter In Motion

NPM Version NPM Downloads

Node.js framework for building applications (cli, server, etc...).

HTTP Transport

Matter In Motion transport extension for HTTP/S protocol.

Installation

  • npm i @matter-in-motion/trasnport
  • npm i @matter-in-motion/trasnports.http

Usage

  1. Add it to your extensions in the settings.
  2. Add settings

Message

Message is simple object that get passed through app. By coming out of this transport it has this properties:

  • url - instance of the URL class
  • decodeBy - mime, Content-Type header
  • encodeBy - mime, Accept header
  • requestHeaders - http request headers with parsed cookies if avaliable
  • requestMethod - http request method
  • request - body of the request
  • connection – http response

Response

To sent response you can set following properties and use transport.send method.

  • responseundefined, null, string, Buffer, or stream
  • responseStatusCode – http response status code
  • responseHeaders - response headers

Settings

  • http/https - make just one
    • server – http.createServer settings
    • listenhttp.listen settings
    • static -
      • url – static url
      • root – static root directory
      • setHeaders – function to set custom headers on response. Alterations to the headers need to occur synchronously.
      • options – send module options

Minimal settings:

settings.http = {
  listen: {
    host: '0.0.0.0',
    port: 3000
  }
}

License: MIT.