httpInterface at Node implemented

This commit is contained in:
Luis Fernando Molina committed 2021-11-13 14:50:24 +01:00
1 parent e91e135ef7
commit 6495cd77de
7 files changed
+73 -7

No files matched your search

@@ -0,0 +1,52 @@
exports.newNetworkModulesHttpInterface = function newNetworkModulesHttpInterface() {
/*
This module represent the HTTP API of the
NNetwork Node. All HTTP request are processed
by this module.
*/
let thisObject = {
initialize: initialize,
finalize: finalize
}
return thisObject
function finalize() {
}
function initialize() {
let port = JSON.parse(NT.networkNode.p2pNetworkNode.node.config).webPort
/*
We will create an HTTP Server and leave it running forever.
*/
SA.nodeModules.http.createServer(onHttpRequest).listen(port)
}
function onHttpRequest(httpRequest, httpResponse) {
try {
let requestPathAndParameters = httpRequest.url.split('?') // Remove version information
let requestPath = requestPathAndParameters[0].split('/')
let endpointOrFile = requestPath[1]
switch (endpointOrFile) {
case 'Signal':
{
let message = requestPath[2]
let response = await thisObject.clientInterface.messageReceived(message)
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(response), httpResponse)
}
break
case 'Stats':
{
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify([]), httpResponse)
}
break
default:
{
}
}
} catch (err) {
console.log(err.stack)
}
}
}