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