Bug fix
- Fixed: bugs in processing GET method - Restored sendToLiveRequests() that was deleted in between commits
This commit is contained in:
parent
70196b004d
commit
a3d2452e4e
@ -1,5 +1,6 @@
|
|||||||
const http = require('http');
|
const http = require('http');
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
|
const url = require('url');
|
||||||
|
|
||||||
module.exports = function Server(port, client, intra) {
|
module.exports = function Server(port, client, intra) {
|
||||||
|
|
||||||
@ -7,21 +8,18 @@ module.exports = function Server(port, client, intra) {
|
|||||||
|
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
if (req.method === "GET") {
|
if (req.method === "GET") {
|
||||||
//GET request (requesting data)
|
//GET: requesting data
|
||||||
req.on('end', () => {
|
let u = url.parse(req.url, true);
|
||||||
let i = req.url.indexOf("?");
|
if (!u.search)
|
||||||
if (i !== -1) {
|
return res.end("");
|
||||||
var request = JSON.parse(req.url.substring(i));
|
client.processRequestFromUser(u.query)
|
||||||
client.processRequestFromUser(request)
|
.then(result => res.end(JSON.parse(result[0])))
|
||||||
.then(result => res.end(JSON.parse(result[0])))
|
.catch(error => res.end(error.toString()));
|
||||||
.catch(error => res.end(error.toString()));
|
|
||||||
};
|
|
||||||
});
|
|
||||||
} else if (req.method === "POST") {
|
} else if (req.method === "POST") {
|
||||||
|
//POST: All data processing (required JSON input)
|
||||||
let data = '';
|
let data = '';
|
||||||
req.on('data', chunk => data += chunk);
|
req.on('data', chunk => data += chunk);
|
||||||
req.on('end', () => {
|
req.on('end', () => {
|
||||||
console.log(data);
|
|
||||||
//process the data storing
|
//process the data storing
|
||||||
client.processIncomingData(data).then(result => {
|
client.processIncomingData(data).then(result => {
|
||||||
res.end(result[0]);
|
res.end(result[0]);
|
||||||
@ -62,6 +60,13 @@ module.exports = function Server(port, client, intra) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function sendToLiveRequests(data) {
|
||||||
|
wsServer.clients.forEach(ws => {
|
||||||
|
if (client.checkIfRequestSatisfy(ws._liveReq, data))
|
||||||
|
ws.send(data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Object.defineProperty(this, "http", {
|
Object.defineProperty(this, "http", {
|
||||||
get: () => server
|
get: () => server
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user