-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (43 loc) · 1.34 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
47
48
49
50
51
52
53
/**
* Created by AntonioGiordano on 25/01/16.
*/
'use strict'
var AzureService = require('./lib/service')
const Joi = require('joi');
const optionsSchema = Joi.object({
client_id: Joi.string(),
client_secret: Joi.string(),
mediaURI: Joi.string().optional(),
tokenURI: Joi.string().optional()
});
exports.register = (server, pluginOptions, next) => {
optionsSchema.validate(pluginOptions, (err, options) => {
if (err) {
return next(err);
}
var amsService = new AzureService(pluginOptions)
amsService.setToken((err) => {
if (err) {
console.log(err)
throw err
} else {
const expose = {
amsService
};
if (pluginOptions.decorate) {
const decorate = pluginOptions.decorate === true ? 'ams-sdk' : pluginOptions.decorate;
server.decorate('server', decorate, expose);
server.decorate('request', decorate, expose);
} else {
Object.keys(expose).forEach((key) => {
server.expose(key, expose[key]);
});
}
next()
}
})
})
}
exports.register.attributes = {
pkg: require('./package.json')
}