-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (39 loc) · 1.32 KB
/
index.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var config = require('serviser-config');
var service = require('serviser');
var Doc = require('./lib/doc.js').Doc;
module.exports.Doc = Doc;
module.exports.swagger = require('./lib/swagger.js');
//backward compatible with serviser < 1.0.0
var App = (service.common && service.common.App) || service.App;
var AppManager = service.AppManager;
/**
* creates Doc app
* @param {Provider} cfg - config
* @param {Object} options - see {App} options for more details
* @param {App} options.app - related App object the documentation should be builded for
*
* @return {App}
*/
AppManager.prototype.buildDoc = function(cfg, options) {
options = options || {};
if (!(options.app instanceof App)) {
throw new Error('Expected `options.app` to be instanceof `App`');
}
var doc = new Doc(this, cfg, options);
doc.on('error', this.$buildAppErrorListener(doc));
this.emit('build-app', doc);
this.add(doc);
return doc;
};
//register DOC server initialization listener
service.Service.on('app', function(app) {
//run doc server
if (app.config.get('doc:listen')) {
var cfg = config.createLiteralProvider(app.config.get('doc'));
cfg.use('memory');
app.appManager.buildDoc(cfg, {
app: app,
name: `${app.name}-doc`
});
}
});