Skip to content

Instantly share code, notes, and snippets.

@eriadam
Last active November 22, 2016 09:30
Show Gist options
  • Save eriadam/a17af27d8ce179beb9675ccbac56cbf8 to your computer and use it in GitHub Desktop.
Save eriadam/a17af27d8ce179beb9675ccbac56cbf8 to your computer and use it in GitHub Desktop.
import * as Config from 'config';
const expressConfig = Config.get('express') as ExpressConfig;
class Bootstrap {
constructor(app) {
let self = this;
// Taking the list from the the config file
let bootstrap = expressConfig.bootstrap;
for (var module of bootstrap) {
self.middleware[module](app);
}
}
middleware = {
/**
* Core components, such as security, compression, responses, body parser.
*/
core: (app) => {
// Security
app.use(Helmet());
// Compression
app.use(Compression());
// Proper error messages
app.use(Boom());
// json body parser
app.use(BodyParser.json());
},
/**
* CORS settings.
* This is configurable in the config files.
*/
cors: (app) => {
var corsOptions = {
credentials: true,
origin: expressConfig.allowOrigin,
};
app.use(CORS(corsOptions));
app.options('*', CORS(corsOptions));
},
/**
* Session management. Configure your settings here.
* e.g. RedisStore
*/
session: (app) => {
const Session = require('express-session');
app.use(Session());
},
};
}
export {Bootstrap};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment