-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
42 lines (33 loc) · 1.16 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
const fastify = require('fastify')({ logger: true });
const path = require('path');
module.exports = class VoicenterWebSDK {
constructor(options = {}) {
this.options = options;
this.config = {
port: 3000,
host: '0.0.0.0',
modulePath: path.join(__dirname + "/../../"),
};
this.config = { ...this.config, ...options };
this.fastify = fastify;
this.routeList = new Map([
['./routes/Ivr', { prefix: '/Ivr', config: this.config }],
['./routes/Cdr', { prefix: '/Cdr', config: this.config }],
['./routes/Popup', { prefix: '/Popup', config: this.config }],
['./routes/PopupApprove', { prefix: '/PopupApprove', config: this.config }],
['./routes/Proxy', { prefix: '/Proxy', config: this.config }],
]);
}
async start() {
try {
this.routeList.forEach((options, route) => {
this.fastify.register(require(route), options);
});
await this.fastify.listen({ port: this.config.port, host: this.config.host });
fastify.log.info(`server listening on ${fastify.server.address().port}`);
} catch (err) {
this.fastify.log.error(err);
process.exit(1);
}
}
}