1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const WebPlugin_1 = require("../web/WebPlugin");
|
4 | const SwaggerMetadataMiddleware_1 = require("./SwaggerMetadataMiddleware");
|
5 | const SwaggerRouterMiddleware_1 = require("./SwaggerRouterMiddleware");
|
6 | const CORSMiddleware_1 = require("./CORSMiddleware");
|
7 | class 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 | }
|
28 | exports.SwaggerPlugin = SwaggerPlugin;
|
29 |
|
\ | No newline at end of file |