mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
handle endpoints with params
This commit is contained in:
parent
e3dfa1ea71
commit
a9c1ce9ca8
@ -20,6 +20,7 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@ragestudio/cloudlink": "^0.5.6",
|
||||
"axios": "^0.21.1",
|
||||
"corenode": "^0.25.9",
|
||||
"cors": "^2.8.5",
|
||||
|
@ -28,8 +28,8 @@ class Server {
|
||||
|
||||
//* set params jails
|
||||
this.routes = []
|
||||
this.endpoints = { ...endpoints }
|
||||
this.middlewares = [...defaultMiddlewares, ...middlewares ?? []]
|
||||
this.endpoints = { ...endpoints, ...this.params.endpoints }
|
||||
this.middlewares = [...defaultMiddlewares, ...middlewares ?? [], ...this.params.middlewares ?? []]
|
||||
this.headers = { ...defaultHeaders, ...this.params.headers }
|
||||
|
||||
//* set server basics
|
||||
@ -80,8 +80,6 @@ class Server {
|
||||
const endpoint = { method: method, route: route, controller: controller }
|
||||
|
||||
this.routes.push(route)
|
||||
this.endpoints[route] = endpoint
|
||||
|
||||
this.httpServer[method.toLowerCase()](route, (req, res, next) => this.httpRequest(req, res, next, endpoint))
|
||||
}
|
||||
|
||||
@ -139,13 +137,11 @@ class Server {
|
||||
next()
|
||||
})
|
||||
|
||||
if (Array.isArray(this.middlewares)) {
|
||||
this.middlewares.forEach((middleware) => {
|
||||
this.httpServer.use(middleware)
|
||||
})
|
||||
}
|
||||
|
||||
if (localEndpoints && Array.isArray(localEndpoints)) {
|
||||
this.endpoints = [...this.endpoints, ...localEndpoints]
|
||||
}
|
||||
|
||||
if (Array.isArray(this.endpoints)) {
|
||||
localEndpoints.forEach((endpoint) => {
|
||||
if (!endpoint || !endpoint.route || !endpoint.controller) {
|
||||
throw new Error(`Invalid endpoint!`)
|
||||
|
Loading…
x
Reference in New Issue
Block a user