godprotocol
Version:
A distributed computing environment for Web 4.0 — integrating AI, decentralisation, and virtual computation.
48 lines (37 loc) • 1.18 kB
JavaScript
import Route_table from "./server/Routable/Route_table.js";
import version_middleware from "./server/version_control.js";
class GodProtocol {
constructor(config) {
this.db_config = config.db_config;
// debug(config, "uhh");
this.api_key = config.api_key;
this.platform_uri = config.platform_uri;
this.route_table = new Route_table(this);
}
platform_db = async () => {
return await this.route_table.platform_db();
};
load_services = async (services) => {
await this.route_table.load_services(services);
};
add_router = async (version, routes, opts = {}) => {
if (opts.is_old) {
await this.route_table.init_version("v1", { is_old: true });
this.route_table.versions[version].routes = routes;
return;
}
await this.route_table.init_version(version);
await this.route_table.load_routes(routes);
};
call = async (route, { headers, body }) => {
return await version_middleware(
{ path: route, headers, body },
null,
this.route_table,
);
};
on_request = async (req, res) => {
await version_middleware(req, res, this.route_table);
};
}
export default GodProtocol;