inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
26 lines • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const SwaggerMetadataMiddleware_1 = require("./SwaggerMetadataMiddleware");
const SwaggerRouterMiddleware_1 = require("./SwaggerRouterMiddleware");
const CORSMiddleware_1 = require("./CORSMiddleware");
class SwaggerPlugin {
constructor(swaggerPath) {
this.name = 'swagger-plugin';
this.swaggerPath = swaggerPath;
}
async willStart(app, context) {
const express = context.get('WebPlugin/APP');
const CORSMiddleware = CORSMiddleware_1.default({
allowedOrigins: app.getConfig('app.cors.allowOrigin', '*'),
allowedHeaders: app.getConfig('app.cors.allowHeaders', ['Content-type']),
allowedMaxAge: app.getConfig('app.cors.maxAge', 300),
});
const meta = new SwaggerMetadataMiddleware_1.default({ swaggerFilePath: this.swaggerPath });
const router = new SwaggerRouterMiddleware_1.default(app.getContext());
await meta.register(express);
express.use(CORSMiddleware);
await router.register(express);
}
}
exports.SwaggerPlugin = SwaggerPlugin;
//# sourceMappingURL=SwaggerPlugin.js.map