mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 18:44:17 +00:00
handle method fixments
This commit is contained in:
parent
d9d7252762
commit
f2dd71ecf6
@ -26,6 +26,11 @@ const helpers = process.runtime.helpers ?? require('@corenode/helpers')
|
|||||||
//* set globals
|
//* set globals
|
||||||
global.SERVER_VERSION = helpers.getVersion()
|
global.SERVER_VERSION = helpers.getVersion()
|
||||||
|
|
||||||
|
const MethodsFix = {
|
||||||
|
"delete": "del",
|
||||||
|
}
|
||||||
|
const ValidMethods = ["get", "post", "put", "patch", "del", "trace", "head"]
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
constructor(params, endpoints, middlewares) {
|
constructor(params, endpoints, middlewares) {
|
||||||
this.params = params ?? {}
|
this.params = params ?? {}
|
||||||
@ -95,9 +100,18 @@ class Server {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix data
|
// check and fix method
|
||||||
controller.method = controller.method?.toLowerCase() ?? "get"
|
controller.method = controller.method?.toLowerCase() ?? "get"
|
||||||
|
|
||||||
|
if (MethodsFix[controller.method]) {
|
||||||
|
controller.method = MethodsFix[controller.method]
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate method
|
||||||
|
if (!ValidMethods.includes(controller.method)){
|
||||||
|
throw new Error(`Invalid endpoint method: ${controller.method}`)
|
||||||
|
}
|
||||||
|
|
||||||
// fulfill an undefined fn
|
// fulfill an undefined fn
|
||||||
if (typeof controller.fn === "undefined") {
|
if (typeof controller.fn === "undefined") {
|
||||||
controller.fn = (req, res, next) => {
|
controller.fn = (req, res, next) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user