UNPKG

1.35 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const WebPlugin_1 = require("../web/WebPlugin");
4const SwaggerMetadataMiddleware_1 = require("./SwaggerMetadataMiddleware");
5const SwaggerRouterMiddleware_1 = require("./SwaggerRouterMiddleware");
6const CORSMiddleware_1 = require("./CORSMiddleware");
7class SwaggerPlugin {
8 constructor(swaggerPath) {
9 this.name = 'swagger-plugin';
10 this.swaggerPath = swaggerPath;
11 }
12 async willStart(app, context) {
13 const express = context.get(WebPlugin_1.default.CONTEXT_APP_KEY);
14 const CORSMiddleware = CORSMiddleware_1.default({
15 allowedOrigins: app.getConfig('app.cors.allowOrigin', '*'),
16 allowedHeaders: app.getConfig('app.cors.allowHeaders', ['Content-type']),
17 allowedMaxAge: app.getConfig('app.cors.maxAge', 300),
18 });
19 const apiKey = app.getConfig('app.apiKey', null);
20 const mdConfig = { apiKey, swaggerFilePath: this.swaggerPath };
21 const meta = new SwaggerMetadataMiddleware_1.default(mdConfig);
22 const router = new SwaggerRouterMiddleware_1.default(app.getContext());
23 await meta.register(express);
24 express.use(CORSMiddleware);
25 await router.register(express);
26 }
27}
28exports.SwaggerPlugin = SwaggerPlugin;
29//# sourceMappingURL=SwaggerPlugin.js.map
\No newline at end of file