billy-http-express

1.4.2 • Public • Published

billy-http-express

Build Status NPM version

A Billy service that creates an Express 4 HTTP server.

Install

$ npm install billy-http-express

Usage

var Application = require('billy');
var HttpService = require('billy-http-express');
 
var app = new Application();
app.service(HttpService);
app.config('http.port', 8889);
 
app.start();

The actual server is started after all services have been loaded, so registering any middleware or setting up of express should happen after this service via the http dependencies.

app.service(function MyWebService(http) {
  http.use(cookieParser());
  http.get('/', function(req, res) {
    res.send('Hello, World!');
  });
});

This can be done in a separate service following this one, or via specifying a module via the http.server config.

Injectables

New dependencies that you can use after adding this service:

tag type description notes
http express The express application Setup routes, middleware, etc with this object

Configs

Available config properties:

config type description default value notes
http.port number Port to listen on for HTTP connections process.env.PORT, 8123 1
http.secret string Server-side secret 'supersecret' Used for securing cookies.
http.webroot string Path to directory of static files to serve null Optional. If not set, will not start the static server. If an array, will serve multiple directories2
http.server function Server startup module null Optional IoC-injected module to start when the server is created. 3
http.username string HTTP basic auth username process.env.HTTP_USERNAME, null If null, any username will be accepted. 4
http.password string HTTP basic auth password process.env.HTTP_PASSWORD, null If null, any password will be accepted. 4

1 Will use the PORT environment variable if available, e.g. on Heroku.

2 The static server is mounted during the start phase of this service, meaning all middleware mounted in the setup / constructor function of other services will have precedence, as will any services that start before this one.

3 The http.server module must be set before the app is started since it is booted with the HTTP service starts.

4 Basic auth will only be enabled if either http.username or http.password is set

Testing

$ npm test

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.4.2
    1
    • latest

Version History

Package Sidebar

Install

npm i billy-http-express

Weekly Downloads

1

Version

1.4.2

License

MIT

Last publish

Collaborators

  • bvalosek