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
@ -6,6 +6,3 @@ new cloudlink.Server({
|
||||
autoInit: true,
|
||||
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) => {
|
||||
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
|
||||
|
@ -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 }
|
||||
|
||||
@ -97,12 +96,11 @@ class Server {
|
||||
|
||||
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,12 +182,15 @@ 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
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user