Skip to content

Commit

Permalink
Revert "feat(engine/network): loopback interface"
Browse files Browse the repository at this point in the history
This reverts commit 38fba12.
  • Loading branch information
FelipeTrost committed Nov 18, 2024
1 parent 885e09d commit 45c0143
Showing 1 changed file with 8 additions and 56 deletions.
64 changes: 8 additions & 56 deletions src/engine/universal/system/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
}

/**
Expand Down Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 45c0143

Please sign in to comment.