mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 10:34:17 +00:00
support method map
This commit is contained in:
parent
6c1d3cb576
commit
11a6b1d260
@ -94,6 +94,8 @@ class Server {
|
||||
|
||||
const endpoint = { method: method, route: route, controller: controller }
|
||||
|
||||
this.endpoints[route] = endpoint
|
||||
|
||||
this.routes.push(route)
|
||||
this.httpServer[method.toLowerCase()](route, (req, res, next) => this.handleRequest(req, res, next, endpoint))
|
||||
}
|
||||
@ -167,9 +169,6 @@ class Server {
|
||||
throw new Error(`Invalid endpoint!`)
|
||||
}
|
||||
|
||||
// add to endpoints map
|
||||
this.endpoints[endpoint.route] = endpoint
|
||||
|
||||
try {
|
||||
let { method, route, controller, fn } = endpoint
|
||||
|
||||
@ -221,8 +220,19 @@ class Server {
|
||||
})
|
||||
|
||||
this.registerEndpoint("get", "/map", (req, res) => {
|
||||
const methods = {}
|
||||
|
||||
this.routes.forEach((route) => {
|
||||
const endpoint = this.endpoints[route] ?? {}
|
||||
|
||||
if (typeof endpoint.method === "string") {
|
||||
methods[route] = endpoint.method
|
||||
}
|
||||
})
|
||||
|
||||
res.json({
|
||||
routes: this.routes
|
||||
routes: this.routes,
|
||||
methods: methods
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user