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

@@ -17236,7 +17236,7 @@
"signingAccountChild": {
"type": "P2P Network Node",
"name": "P2P Network Node # 1",
"config": "{\n \"codeName\": \"P2P-Network-Node-1\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18042\"\n}",
"config": "{\n \"codeName\": \"P2P-Network-Node-1\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18042\",\n \"webPort\": \"31248\"\n}",
"project": "Governance",
"id": "bb0f0417-9dfb-47a3-941f-dcfa82fbaea1",
"savedPayload": {
@@ -17292,7 +17292,7 @@
"signingAccountChild": {
"type": "P2P Network Node",
"name": "P2P Network Node # 2",
"config": "{\n \"codeName\": \"P2P-Network-Node-2\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18043\"\n}",
"config": "{\n \"codeName\": \"P2P-Network-Node-2\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18043\",\n \"webPort\": \"31248\"\n}",
"project": "Governance",
"id": "76fa8a24-9ab4-4eaf-82f2-458ba557b204",
"savedPayload": {
@@ -17348,7 +17348,7 @@
"signingAccountChild": {
"type": "P2P Network Node",
"name": "P2P Network Node # 3",
"config": "{\n \"codeName\": \"P2P-Network-Node-3\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18044\"\n}",
"config": "{\n \"codeName\": \"P2P-Network-Node-3\",\n \"host\": \"localhost\",\n \"webSocketsPort\": \"18044\",\n \"webPort\": \"31248\"\n}",
"project": "Governance",
"id": "297e57c2-3c1a-4170-b710-d2705804205b",
"savedPayload": {
@@ -25,7 +25,7 @@
"config": true
},
"initialValues": {
"config": "{ \n\"codeName\": \"localhost\", \n\"host\": \"localhost\", \n\"webSocketsPort\": \"18042\"\n}"
"config": "{ \n\"codeName\": \"localhost\", \n\"host\": \"localhost\", \n\"webPort\": \"31248\", \n\"webSocketsPort\": \"18042\"\n}"
},
"addLeftIcons": true,
"level": 1,
@@ -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)
}
}
}
+7 -1
View File
@@ -1389,6 +1389,12 @@
"propertyName": "webSocketsInterface",
"functionName": "newNetworkModulesWebSocketsInterface",
"fileName": "WebSocketsInterface.js"
},
{
"name": "Http Interface",
"propertyName": "httpInterface",
"functionName": "newNetworkModulesHttpInterface",
"fileName": "HttpInterface.js"
}
],
"utilities": []
@@ -1629,7 +1635,7 @@
"name": "Http Interface",
"propertyName": "httpInterface",
"functionName": "newDesktopModulesHttpInterface",
"fileName": "httpInterface.js"
"fileName": "HttpInterface.js"
},
{
"name": "Web Sockets Interface",
@@ -64,7 +64,7 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule
return await eventReceived(messageHeader.eventMessage, userProfile)
}
case 'Signal': {
return await signalReceived(messageHeader.eventMessage, userProfile)
return await signalReceived(messageHeader.eventMessage)
}
}
}
@@ -245,7 +245,7 @@ exports.newSocialTradingModulesClientInterface = function newSocialTradingModule
}
}
async function signalReceived(signalMessage, userProfile) {
async function signalReceived(signalMessage) {
/*
We expect here a JSON string with some or all of the following properties: