(app: IMidwayApplication)
| 47 | } |
| 48 | |
| 49 | resolve(app: IMidwayApplication) { |
| 50 | if (app.getNamespace() === 'express') { |
| 51 | return async (req: any, res: any, next: NextFunction) => { |
| 52 | const pathname = req.path; |
| 53 | const renderResult = await this.swaggerRender(pathname); |
| 54 | |
| 55 | if (renderResult) { |
| 56 | const { ext, content } = renderResult; |
| 57 | if (ext === '.js') { |
| 58 | res.type('application/javascript'); |
| 59 | } else if (ext === '.map') { |
| 60 | res.type('application/json'); |
| 61 | } else if (ext === '.css') { |
| 62 | res.type('text/css'); |
| 63 | } else if (ext === '.png') { |
| 64 | res.type('image/png'); |
| 65 | } |
| 66 | res.send(content); |
| 67 | } else { |
| 68 | return next(); |
| 69 | } |
| 70 | }; |
| 71 | } else { |
| 72 | return async (ctx: IMidwayContext, next: NextFunction) => { |
| 73 | const pathname = (ctx as any).path; |
| 74 | const renderResult = await this.swaggerRender(pathname); |
| 75 | |
| 76 | if (renderResult) { |
| 77 | const { ext, content } = renderResult; |
| 78 | if (ext === '.js') { |
| 79 | (ctx as any).set('Content-Type', 'application/javascript'); |
| 80 | } else if (ext === '.map') { |
| 81 | (ctx as any).set('Content-Type', 'application/json'); |
| 82 | } else if (ext === '.css') { |
| 83 | (ctx as any).set('Content-Type', 'text/css'); |
| 84 | } else if (ext === '.png') { |
| 85 | (ctx as any).set('Content-Type', 'image/png'); |
| 86 | } |
| 87 | |
| 88 | (ctx as any).body = content; |
| 89 | } else { |
| 90 | return next(); |
| 91 | } |
| 92 | }; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | static getName() { |
| 97 | return 'swagger'; |
nothing calls this directly
no test coverage detected