From 45c0143564343e32b06b317758682e2e948e3e61 Mon Sep 17 00:00:00 2001 From: Felipe Trost Date: Mon, 18 Nov 2024 12:03:22 +0100 Subject: [PATCH] Revert "feat(engine/network): loopback interface" This reverts commit 38fba12646b30f1ceae0968651bf6dd7edf6889c. --- src/engine/universal/system/src/network.js | 64 +++------------------- 1 file changed, 8 insertions(+), 56 deletions(-) diff --git a/src/engine/universal/system/src/network.js b/src/engine/universal/system/src/network.js index 9f949bba2..768aa7d10 100644 --- a/src/engine/universal/system/src/network.js +++ b/src/engine/universal/system/src/network.js @@ -17,12 +17,6 @@ class Network { this._http = new HTTP(env); this.environment = env; this._messaging = messaging; - this._callbacks = { - get: new Map(), - put: new Map(), - post: new Map(), - delete: new Map(), - }; } /** @@ -80,65 +74,23 @@ class Network { } get(path, options, callback) { - const wrappedCallback = wrapInFilterResponseMiddleware(callback); - this._callbacks.get.set(path, wrappedCallback); - this._http.get(path, options, wrappedCallback); - this._messaging.get(path, options, wrappedCallback); + this._http.get(path, options, wrapInFilterResponseMiddleware(callback)); + this._messaging.get(path, options, wrapInFilterResponseMiddleware(callback)); } put(path, options, callback) { - const wrappedCallback = wrapInFilterResponseMiddleware(callback); - this._callbacks.get.set(path, wrappedCallback); - this._http.put(path, options, wrappedCallback); - this._messaging.put(path, options, wrappedCallback); + this._http.put(path, options, wrapInFilterResponseMiddleware(callback)); + this._messaging.put(path, options, wrapInFilterResponseMiddleware(callback)); } post(path, options, callback) { - const wrappedCallback = wrapInFilterResponseMiddleware(callback); - this._callbacks.post.set(path, wrappedCallback); - this._http.post(path, options, wrappedCallback); - this._messaging.post(path, options, wrappedCallback); + this._http.post(path, options, wrapInFilterResponseMiddleware(callback)); + this._messaging.post(path, options, wrapInFilterResponseMiddleware(callback)); } delete(path, options, callback) { - const wrappedCallback = wrapInFilterResponseMiddleware(callback); - this._callbacks.delete.set(path, wrappedCallback); - this._http.delete(path, options, wrappedCallback); - this._messaging.delete(path, options, wrappedCallback); - } - - /** - * Call endpoints from within the engine - * - * @param {string} method The method to use for the request - * @param {string} path The path to the endpoint - * @param {{ - hostname?: string; - ip?: string; - method?: string; - params?: any; - query?: any; - path?: string; - body?: any; - files?: any; - }} reqObject The request object to pass to the endpoint - * @throws {Error} If the method isn't supported, if no callback is registered for the path, or - * if the callback for the path throws an error - */ - async loopback(method, path, reqObject) { - if (!(method in this._callbacks)) throw new Error(`Method ${method} not supported`); - - const alternatePath = path.endsWith('/') ? path.slice(0, -1) : `${path}/`; - const callback = - this._callbacks[method].get(path) || this._callbacks[method].get(alternatePath); - if (!callback) throw new Error(`No callback registered for path ${path}`); - - if (!reqObject) reqObject = {}; - if (!('query' in reqObject)) reqObject.query = {}; - if (!('method' in reqObject)) reqObject.method = method.toUpperCase(); - if (!('path' in reqObject)) reqObject.path = path; - - return await callback(reqObject); + this._http.delete(path, options, wrapInFilterResponseMiddleware(callback)); + this._messaging.delete(path, options, wrapInFilterResponseMiddleware(callback)); } }