-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_express2.js
132 lines (87 loc) · 2.66 KB
/
server_express2.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//Preparing the application to start'
var express = "";
var bodyParser = "";
//Prepare For Logging
var logConfig = {
appenders: {
everything: { type: 'file', filename: './log/logging.log' }
},
categories: {
default: { appenders: [ 'everything' ], level: 'debug' }
}
};
var log = require('log4js').configure(logConfig);
const logger = log.getLogger();
//Load Configuration File
var appConfig = "";
var loadingApp = false;
var port = "";
var requestHeader = "";
var diURL = [];
var pgURL = [];
var conURL = [];
var battURL = [];
var warnURL = "";
//MQTT
var mqtt = "";
var clientMqtt = "";
//Socket.io
//const io = "";
try{
appConfig = require('./config/app_config.js');
express = require('express');
bodyParser = require('body-parser');
//io = require('socket.io')(19997);
//PORT
port = appConfig.port;
requestHeader = {
"header" : {
"Accept" : appConfig.requestHeader.Accept,
"X-M2M-RI" : appConfig.requestHeader.XM2MRI,
"X-M2M-Origin" : appConfig.requestHeader.XM2MOrigin
}
}
//Flag for running the application
loadingApp = true;
}catch(e){
console.log("Application is failed to start. "+e);
logger.error("Application is failed to start. "+e);
}
if(loadingApp){
const util = require('util');
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
const io = require('socket.io')(19997,{ origins: '*:*'});
app.post('/solar', (req, res) => {
res = setReponseHeader(res);
res.statusCode = 200 ;
res.send("Successful");
//console.log("Incoming Solar Data = "+JSON.stringify(req.body));
/*var worker = getRequestedData;
try{
console.log("Push Solar Data.");
worker.doWork(req, res, "Solar",solarEventEntityName, solarChannelName, io);
}catch(e){
console.log("Failed to Retrieve and to Push Solar Data" +e);
}
finally{
delete worker;
}*/
io.on('connection', function(socket){
//socket.emit('sendDeviceLocation', 'my device location');
console.log("Help Me hhhhhhhhhhhhhhhhh");
});
var pusher = io.of('/solarCurrent').on('connection', function(socket){
console.log("Push to Client!");
//socket.emit('current', req.body);
});
});
function setReponseHeader(res){
res.setHeader('Content-Type', 'application/json');
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
return res;
}
app.listen(port, () => console.log('This app is listening on port 19998! and with POST listening and web socket is on port 19997!'));
}