refactor map generator

This commit is contained in:
srgooglo 2021-07-28 09:45:37 +02:00
parent e1cff3b583
commit 37e60153a9
3 changed files with 13 additions and 28 deletions

View File

@ -5,7 +5,4 @@ const random = require("corenode/dist/libs/random")
new cloudlink.Server({
autoInit: true,
id: runtime.args.id ?? random.generateName(),
})
new cloudlink.Client.createInterface("http://localhost:3010").then((client) => {
})

View File

@ -115,11 +115,13 @@ async function createInterface(address, getContext) {
Object.keys(map).forEach((method) => {
method = method.toLowerCase()
if (typeof objects[method] !== "object") {
objects[method] = Object()
}
Object.keys(map[method]).forEach((route) => {
map[method].forEach((endpoint) => {
const route = endpoint.route
const tree = route.split("/")
const hasTree = tree.length >= 1
let nameKey = route

View File

@ -40,10 +40,9 @@ class Server {
}
//* set params jails
this.routes = []
this.endpoints = {}
this.serverMiddlewares = [...this.params.serverMiddlewares ?? [], ...defaultMiddlewares]
this.middlewares = { ...this.params.middlewares }
this.middlewares = { ...this.params.middlewares, ...middlewares }
this.controllers = { ...this.params.controllers }
this.headers = { ...defaultHeaders, ...this.params.headers }
@ -94,15 +93,14 @@ class Server {
if (typeof endpoint.controller === "function") {
endpoint.controller = new classes.Controller(endpoint.route, endpoint.controller)
}
endpoint.method = endpoint.method.toLowerCase()
if (typeof this.endpoints[endpoint.method] !== "object") {
if (typeof this.endpoints[endpoint.method] === "undefined") {
this.endpoints[endpoint.method] = Object()
}
this.endpoints[endpoint.method][endpoint.route] = endpoint
this.routes.push(endpoint.route)
const routeModel = [endpoint.route]
@ -177,21 +175,6 @@ class Server {
}
})
this.registerEndpoint({
method: "PUT",
route: "/session",
controller: (req, res) => {
res.send("bruh")
}
})
this.registerEndpoint({
method: "DELETE",
route: "/session",
controller: (req, res) => {
res.send("deleted bruh")
}
})
this.registerEndpoint({
method: "get",
route: "/map",
@ -199,15 +182,18 @@ class Server {
const map = {}
Object.keys(this.endpoints).forEach((method) => {
if (typeof map[method] !== "object") {
map[method] = Object()
if (typeof map[method] === "undefined") {
map[method] = []
}
Object.keys(this.endpoints[method]).forEach((route) => {
map[method] = route
map[method].push({
route: route,
method: method
})
})
})
res.json(map)
}
})