7.2.0 • Published 2 years ago

volante-express v7.2.0

Weekly downloads
3
License
ISC
Repository
github
Last release
2 years ago

Volante Spoke for Express.js

Neatly encapsulates an express.js server for use in a Volante wheel.

Features

  • allows other Volante Spokes to register their Express middleware
  • Express logging emitted as Volante events

Usage

npm install volante-express

Volante Spokes are automatically loaded and instanced if they are installed locally and hub.attachAll() is called.

Props

Options can be changed using the VolanteExpress.update event with an object:

hub.emit('VolanteExpress.update', {
  autoStart: true,                 // automatically start
  bind: '127.0.0.1',               // bind address
  port: 3000,                      // server port
  https: false,                    // enable https mode
  cert: null,                      // tls certificate
  key: null,                       // tls private key
  logging: true,                   // emit express log as Volante events
  cors: []                         // CORS entries, adding to array enables cors
  middleware: [                    // express middleware
    // array of express middleware, e.g.:
    require('compression')()
  ]
});

or specify any of the above in a config.json file as fields under a VolanteExpress object and pass it to the hub: hub.loadConfig('config.json').

Events

Handled

  • VolanteExpress.use - .use() call for middleware (enables self-registering volante middleware)
    Object // middleware object used for .use() call
  • VolanteExpress.start - start the server (call this LAST, after all middleware has been added)
  • VolanteExpress.stop - stop the server

Emitted

In addition to native Volante log events, this modules also emits:

  • VolanteExpress.router(router) - preferred way to register routes, call the supplied router param to get a router instance
    events: {
      'VolanteExpress.router'(router) {
        let r = router();
        r.get('/').then((req, res) => {});
      }
    }
  • VolanteExpress.app(app) - preferred way for other spokes to register their middleware, example:
    events: {
      'VolanteExpress.app'(app) {
        app.use(this.localRouter);
      }
    }
  • VolanteExpress.listening({ bind: String, port: Number})

Logs

If logging is enabled, Express.js HTTP requests are logged to volante log events with the following content structure:

{
  method: String,
  src: String,
  url: String,
  status: Number,
  ms: Number
}

License

ISC

7.2.0

2 years ago

7.1.0

2 years ago

6.3.0

2 years ago

7.0.0

2 years ago

6.1.0

2 years ago

6.0.0

2 years ago

6.2.0

2 years ago

5.0.0

2 years ago

4.1.0

2 years ago

4.2.0

2 years ago

4.0.0

3 years ago

3.0.0

3 years ago

2.11.0

3 years ago

2.10.0

3 years ago

2.9.3

3 years ago

2.9.2

4 years ago

2.9.1

4 years ago

2.9.0

4 years ago

2.8.1

4 years ago

2.8.0

5 years ago

2.7.0

5 years ago

2.6.1

5 years ago

2.6.0

5 years ago

2.5.0

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.7

5 years ago

2.2.6

5 years ago

2.2.5

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.2

7 years ago

1.0.1

7 years ago