kobp
Version:
Koa Boilerplate with MikroORM
47 lines • 1.67 kB
JavaScript
import bodyParser from 'koa-bodyparser';
import { withJson } from '../middlewares';
import { // Lang to force module registrations
RequestRoomProvider, } from '../utils';
export class BootstrapModule {
constructor(opts) {
if (opts && typeof opts === 'function') {
this.bodyParserOptions = opts();
}
else {
const resolveAllowedBodyTypes = (() => {
if (opts && Array.isArray(opts)) {
return opts;
}
return `${(process.env.KOBP_ALLOWED_BODY_TYPES || 'json,form')}`.trim().split(',').filter(Boolean);
});
this.bodyParserOptions = {
enableTypes: resolveAllowedBodyTypes(),
// Enhance this to use Function instead.
jsonLimit: '10mb',
textLimit: '10mb',
xmlLimit: '10mb',
formLimit: '10mb',
};
}
}
/**
* Override this function to provide the customized module
*/
customization() {
return {
onInit: async () => {
},
middlewares: (app) => {
app.use(bodyParser(this.bodyParserOptions));
// automatically create the required instances.
app.use((ctx, next) => RequestRoomProvider.shared.createAsync(ctx, next));
// withJson will have no access to Loggy!
app.use(withJson());
},
onSignalReceived: async (_signal, _app) => {
// gracefully shutting this down.
},
};
}
}
//# sourceMappingURL=bootstrap.module.js.map