mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
refactor map generator
This commit is contained in:
parent
e1cff3b583
commit
37e60153a9
@ -5,7 +5,4 @@ const random = require("corenode/dist/libs/random")
|
|||||||
new cloudlink.Server({
|
new cloudlink.Server({
|
||||||
autoInit: true,
|
autoInit: true,
|
||||||
id: runtime.args.id ?? random.generateName(),
|
id: runtime.args.id ?? random.generateName(),
|
||||||
})
|
|
||||||
|
|
||||||
new cloudlink.Client.createInterface("http://localhost:3010").then((client) => {
|
|
||||||
})
|
})
|
@ -115,11 +115,13 @@ async function createInterface(address, getContext) {
|
|||||||
|
|
||||||
Object.keys(map).forEach((method) => {
|
Object.keys(map).forEach((method) => {
|
||||||
method = method.toLowerCase()
|
method = method.toLowerCase()
|
||||||
|
|
||||||
if (typeof objects[method] !== "object") {
|
if (typeof objects[method] !== "object") {
|
||||||
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 tree = route.split("/")
|
||||||
const hasTree = tree.length >= 1
|
const hasTree = tree.length >= 1
|
||||||
let nameKey = route
|
let nameKey = route
|
||||||
|
@ -40,10 +40,9 @@ class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//* set params jails
|
//* set params jails
|
||||||
this.routes = []
|
|
||||||
this.endpoints = {}
|
this.endpoints = {}
|
||||||
this.serverMiddlewares = [...this.params.serverMiddlewares ?? [], ...defaultMiddlewares]
|
this.serverMiddlewares = [...this.params.serverMiddlewares ?? [], ...defaultMiddlewares]
|
||||||
this.middlewares = { ...this.params.middlewares }
|
this.middlewares = { ...this.params.middlewares, ...middlewares }
|
||||||
this.controllers = { ...this.params.controllers }
|
this.controllers = { ...this.params.controllers }
|
||||||
this.headers = { ...defaultHeaders, ...this.params.headers }
|
this.headers = { ...defaultHeaders, ...this.params.headers }
|
||||||
|
|
||||||
@ -94,15 +93,14 @@ class Server {
|
|||||||
if (typeof endpoint.controller === "function") {
|
if (typeof endpoint.controller === "function") {
|
||||||
endpoint.controller = new classes.Controller(endpoint.route, endpoint.controller)
|
endpoint.controller = new classes.Controller(endpoint.route, endpoint.controller)
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint.method = endpoint.method.toLowerCase()
|
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] = Object()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.endpoints[endpoint.method][endpoint.route] = endpoint
|
this.endpoints[endpoint.method][endpoint.route] = endpoint
|
||||||
this.routes.push(endpoint.route)
|
|
||||||
|
|
||||||
const routeModel = [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({
|
this.registerEndpoint({
|
||||||
method: "get",
|
method: "get",
|
||||||
route: "/map",
|
route: "/map",
|
||||||
@ -199,15 +182,18 @@ class Server {
|
|||||||
const map = {}
|
const map = {}
|
||||||
|
|
||||||
Object.keys(this.endpoints).forEach((method) => {
|
Object.keys(this.endpoints).forEach((method) => {
|
||||||
if (typeof map[method] !== "object") {
|
if (typeof map[method] === "undefined") {
|
||||||
map[method] = Object()
|
map[method] = []
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(this.endpoints[method]).forEach((route) => {
|
Object.keys(this.endpoints[method]).forEach((route) => {
|
||||||
map[method] = route
|
map[method].push({
|
||||||
|
route: route,
|
||||||
|
method: method
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json(map)
|
res.json(map)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user