1.4.2 • Published 10 years ago

billy-http-express v1.4.2

Weekly downloads
4
License
MIT
Repository
github
Last release
10 years ago

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:

tagtypedescriptionnotes
httpexpressThe express applicationSetup routes, middleware, etc with this object

Configs

Available config properties:

configtypedescriptiondefault valuenotes
http.portnumberPort to listen on for HTTP connectionsprocess.env.PORT, 8123 1
http.secretstringServer-side secret'supersecret'Used for securing cookies.
http.webrootstringPath to directory of static files to servenullOptional. If not set, will not start the static server. If an array, will serve multiple directories2
http.serverfunctionServer startup modulenullOptional IoC-injected module to start when the server is created. 3
http.usernamestringHTTP basic auth usernameprocess.env.HTTP_USERNAME, nullIf null, any username will be accepted. 4
http.passwordstringHTTP basic auth passwordprocess.env.HTTP_PASSWORD, nullIf 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

1.4.2

10 years ago

1.4.1

10 years ago

1.4.0

10 years ago

1.3.0

10 years ago

1.2.0

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.0.0

10 years ago