kobp
Version:
Koa Boilerplate with MikroORM
53 lines • 1.99 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BootstrapModule = void 0;
const koa_bodyparser_1 = __importDefault(require("koa-bodyparser"));
const middlewares_1 = require("../middlewares");
const utils_1 = require("../utils");
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((0, koa_bodyparser_1.default)(this.bodyParserOptions));
// automatically create the required instances.
app.use((ctx, next) => utils_1.RequestRoomProvider.shared.createAsync(ctx, next));
// withJson will have no access to Loggy!
app.use((0, middlewares_1.withJson)());
},
onSignalReceived: async (_signal, _app) => {
// gracefully shutting this down.
},
};
}
}
exports.BootstrapModule = BootstrapModule;
//# sourceMappingURL=bootstrap.module.js.map