0.2.1 • Published 5 years ago

@keystonejs-contrib/app-express v0.2.1

Weekly downloads
4
License
MIT
Repository
-
Last release
5 years ago

section: packages

title: Express App

Express App

This package helps create custom middleware using express config

initialize

Constructor

new ExpressApp({
  app = express(),
  ...expressOptions
}, configureExpress = app => {})

Paremeters

  • app: used for providing custom express instance.
  • expressOptions: all those things can be set using app.set(key, value)
  • configureExpress: function argument which will be called similar to configureExpress method.

    expressOptions can be skipped altogether and only configureExpress may be used

example:
const customApp = new ExpressApp({
    views: './templates',
    'view engine': 'pug',
  },
  app => {
    app.use(bodyParser.urlencoded({ extended: true }));
    someOtherMethod(keystone, app);
  }
);

// OR when skipping expressOptions

new ExpressApp(app => {
  app.set(...);
  app.use(...);
  app.get(...);
  app.post(...);
})

Methods

configureExpress(fn)

useful for configuring the express instance for more settings.

const customApp = new ExpressApp({....config});
customApp.configureExpress(app => {
  app.use(....);
  someOthermethod(app);
})
use(middleware)

proxy for app.use method for express instance wrapped inside

const customApp = new ExpressApp({....config});
customApp.use(bodyParser());
set(key, value)

proxy for app.set method for express instance wrapped inside

const customApp = new ExpressApp({....config});
customApp.set('my option', 'my value');