Last active
November 22, 2016 09:30
-
-
Save eriadam/a17af27d8ce179beb9675ccbac56cbf8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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