-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathapi.js
53 lines (42 loc) · 1.29 KB
/
api.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
const Express = require('express');
const bodyParser = require('body-parser');
const configuration = require("./lib/config/config.js");
// console.log('argv:');
// console.log(process.argv);
configuration.init(process.argv.slice(2));
const assistant = require("./lib/assistant");
const callback = require("./lib/callback");
const device = require("./lib/device");
const config = require("./lib/config");
const deviceId = require("./lib/device/id");
const swagger = require("./lib/swagger");
startApi();
function startApi() {
console.log('cast-web-api v'+configuration.thisVersion);
createWebServer();
}
function createWebServer() {
const webserver = Express();
webserver.use(bodyParser.json());
webserver.use(assistant);
webserver.use(callback);
webserver.use(device);
webserver.use(deviceId);
webserver.use(config);
webserver.use(swagger);
webserver.get('/', function (req, res) {
res.json({castWebApi: `v${configuration.thisVersion}`});
});
webserver.listen(configuration.port, () => {
console.log(`cast-web-api running at http://${configuration.hostname}:${configuration.port}`);
});
process.on('message', packet => {
console.log(configuration.hostname);
process.send({
type : 'process:msg',
data : {
address : `${configuration.hostname}:${configuration.port}`
}
});
});
}