-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathapp.js
29 lines (24 loc) · 808 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
const pathToSwaggerUi = require('swagger-ui-dist').absolutePath();
const Swagger = require('./lib/swagger');
class AppBootHook {
constructor(app) {
this.app = app;
}
configWillLoad() {
let staticDirs = this.app.config.static.dir;
// CAUTION: index.html under 'app/public' directory will be overwrite by 'swagger-ui-dist'
if (Array.isArray(staticDirs)) staticDirs.unshift(pathToSwaggerUi);
else staticDirs = [pathToSwaggerUi, staticDirs];
this.app.config.static.dir = staticDirs;
}
didLoad() {
try {
new Swagger(this.app, pathToSwaggerUi);
this.app.logger.info(`[swagger-egg] Swagger document initing succeed!`);
} catch (error) {
this.app.logger.error(`[swagger-egg] ${error.message}`);
}
}
}
module.exports = AppBootHook;