fix methods

This commit is contained in:
srgooglo 2021-11-15 13:34:17 +01:00
parent 9834099f49
commit daf2885f39

View File

@ -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,8 +108,8 @@ 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