service-host
Installation
npm install service-host
CLI usage
# Start up a service host node bin/start.js --config path/to/config.js
Config files should export an object.
Programmatic usage
var Host = ; var host = debug: true port: 9000; host; // Call a servicehost; // Start a process which listens at the configured// address and porthost;
Communicating with the host
Headers
X-Service
: the name of the service that you want to call.X-Cache-Key
: a token used to cache the output of the request, all concurrent or subsequent requests will resolve to the same output until it expires.
Sending data
Set the request's content-type to application/json
and pass the data in
as the request's body. It will be deserialised and passed to the service.
Configuring the host
// Default config var host = // The address that the host will listen at address: '127.0.0.1' // The port that the host will listen at port: '63578' // If true, suppresses stdout/stderr from the host and service loggers silent: false // If true, the host will write to stdout once it is listening for requests outputOnListen: true // The maximum size of an incoming request's body requestDataLimit: '10mb' // The time between a cache key/value being set and its expiry serviceCacheTimeout: 24 * 60 * 60 * 1000 // 24 hours // An optional array of services to load during the host's initialization. // Services should be objects with `name` and either `file` or `handler` // properties. The `file` prop should be a path to a file which exports a // handler function. services: null;