mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 18:44:17 +00:00
fix methods
This commit is contained in:
parent
9834099f49
commit
daf2885f39
@ -9,23 +9,29 @@ const nethub = require("../../lib/nethub")
|
|||||||
const { getLocalEndpoints, fetchController, serverManifest } = require("../../lib")
|
const { getLocalEndpoints, fetchController, serverManifest } = require("../../lib")
|
||||||
const hostAddress = net.ip.getHostAddress() ?? "localhost"
|
const hostAddress = net.ip.getHostAddress() ?? "localhost"
|
||||||
|
|
||||||
const defaultMiddlewares = [
|
|
||||||
require('cors')(),
|
|
||||||
require('morgan')("dev"),
|
|
||||||
]
|
|
||||||
const defaultHeaders = {
|
const defaultHeaders = {
|
||||||
"Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept, Authorization",
|
"Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Accept, Authorization",
|
||||||
"Access-Control-Allow-Origin": "*",
|
"Access-Control-Allow-Origin": "*",
|
||||||
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, PATCH, DELETE",
|
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, PATCH, DELETE, DEL",
|
||||||
"Access-Control-Allow-Credentials": "true",
|
"Access-Control-Allow-Credentials": "true",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultMiddlewares = [
|
||||||
|
require('cors')({
|
||||||
|
"origin": "*",
|
||||||
|
"methods": defaultHeaders["Access-Control-Allow-Methods"],
|
||||||
|
"preflightContinue": false,
|
||||||
|
"optionsSuccessStatus": 204
|
||||||
|
}),
|
||||||
|
require('morgan')("dev"),
|
||||||
|
]
|
||||||
|
|
||||||
const helpers = process.runtime.helpers ?? require('@corenode/helpers')
|
const helpers = process.runtime.helpers ?? require('@corenode/helpers')
|
||||||
|
|
||||||
//* set globals
|
//* set globals
|
||||||
global.SERVER_VERSION = helpers.getVersion()
|
global.SERVER_VERSION = helpers.getVersion()
|
||||||
|
|
||||||
const MethodsFix = {
|
const FixedMethods = {
|
||||||
"delete": "del",
|
"delete": "del",
|
||||||
}
|
}
|
||||||
const ValidMethods = ["get", "post", "put", "patch", "del", "trace", "head", "any", "options", "ws"]
|
const ValidMethods = ["get", "post", "put", "patch", "del", "trace", "head", "any", "options", "ws"]
|
||||||
@ -102,12 +108,12 @@ class Server {
|
|||||||
// check and fix method
|
// check and fix method
|
||||||
controller.method = controller.method?.toLowerCase() ?? "get"
|
controller.method = controller.method?.toLowerCase() ?? "get"
|
||||||
|
|
||||||
if (MethodsFix[controller.method]) {
|
if (FixedMethods[controller.method]) {
|
||||||
controller.method = MethodsFix[controller.method]
|
controller.method = FixedMethods[controller.method]
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate method
|
// validate method
|
||||||
if (!ValidMethods.includes(controller.method)){
|
if (!ValidMethods.includes(controller.method)) {
|
||||||
throw new Error(`Invalid endpoint method: ${controller.method}`)
|
throw new Error(`Invalid endpoint method: ${controller.method}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user