diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js index 04696158e2b02a6f7d7721fdaad4cca05f514aa5..2b9eb04a1ba807b400eca7abbd8d34b094ebcab4 100644 --- a/web-service/server/src/index.js +++ b/web-service/server/src/index.js @@ -276,6 +276,14 @@ function broadcastExcept(exc, name, ...args) { } } +function locateConfigPeer(uri) { + let cur_uri = uri; + while (cur_uri.length > 0 && !cfg_to_peer.hasOwnProperty(cur_uri)) { + cur_uri = cur_uri.substring(0, cur_uri.lastIndexOf('/')); + } + return (cur_uri.length > 0) ? cfg_to_peer[cur_uri] : null; +} + app.ws('/', (ws, req) => { console.log("New web socket request"); @@ -471,11 +479,9 @@ app.ws('/', (ws, req) => { * Update certain URIs values */ p.bind("update_cfg", (uri, json) => { - const parsedURI = stringSplitter(uri) - console.log("URI", uri) - console.log("JSON", json) - if(uri_to_peer[parsedURI]){ - let peer = uri_to_peer[parsedURI] + let peer = locateConfigPeer(uri); + + if (peer) { peer.send("update_cfg", uri, json) }else{ console.log("Failed to update the configuration uri", uri)