UNPKG

inceptum

Version:

hipages take on the foundational library for enterprise-grade apps written in NodeJS

30 lines 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SwaggerPlugin = void 0; const WebPlugin_1 = require("../web/WebPlugin"); 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_1.default.CONTEXT_APP_KEY); const CORSMiddleware = (0, 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 apiKey = app.getConfig('app.apiKey', null); const mdConfig = { apiKey, swaggerFilePath: this.swaggerPath }; const meta = new SwaggerMetadataMiddleware_1.default(mdConfig); 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