-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpserver.js
67 lines (56 loc) · 1.92 KB
/
httpserver.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const debug = require('debug')('acs-http:debug')
, info = require('debug')('acs-http:info')
, express = require('express')
, app = express()
, bodyParser = require('body-parser')
, engine = require('express-ejs-layouts')
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
, monitor = require('./monitor.js')(io)
, fs = require('fs');
/* Setting to use socket.io */
app.server = server;
app.io = io;
/* Setup ejs template engine */
app.set('view engine', 'ejs');
app.set('views', __dirname + '/webui');
app.set('layout', 'layout');
/* always using ejs-layout module */
app.use(engine);
/* Use request body parser */
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
/* Define Static Files Path */
app.use('/images', express.static(__dirname + '/webui/images'));
app.use('/script', express.static(__dirname + '/webui/script'));
app.use('/style', express.static(__dirname + '/webui/style'));
app.use('/script/bootbox.min.js', express.static(__dirname + '/node_modules/bootbox/bootbox.min.js'));
app.get('/', function(req, res) {
res.render('index');
});
/* ACS Plug-in Setup Read / Write */
app.get('/read-setup', function(req, res) {
res.json(fs.readFileSync('config.json', 'utf8'));
}).post('/write-setup', function(req, res) {
process.send({ command: 'config', config: req.body });
res.status(200).end();
});
/* ACS Plug-in Start / Stop */
app.get('/start_plugin', function(req, res) {
process.send({ command: 'start_plugin' });
res.status(200).end();
}).get('/stop_plugin', function(req, res) {
process.send({ command: 'stop_plugin' });
res.status(200).end();
});
app.get('/monitor', function(req, res) {
res.render('monitor');
});
var port = Number(process.argv[2]);
server.listen(port, function() {
info("Http server listening on port %d (PID : %d)", port, process.pid);
});
// Process SIGNAL Event Listening
process.on('SIGINT', function() {
process.exit();
});