Projektstart
This commit is contained in:
36
backend/node_modules/find-my-way/lib/strategies/accept-host.js
generated
vendored
Normal file
36
backend/node_modules/find-my-way/lib/strategies/accept-host.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict'
|
||||
const assert = require('node:assert')
|
||||
|
||||
function HostStorage () {
|
||||
const hosts = {}
|
||||
const regexHosts = []
|
||||
return {
|
||||
get: (host) => {
|
||||
const exact = hosts[host]
|
||||
if (exact) {
|
||||
return exact
|
||||
}
|
||||
for (const regex of regexHosts) {
|
||||
if (regex.host.test(host)) {
|
||||
return regex.value
|
||||
}
|
||||
}
|
||||
},
|
||||
set: (host, value) => {
|
||||
if (host instanceof RegExp) {
|
||||
regexHosts.push({ host, value })
|
||||
} else {
|
||||
hosts[host] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'host',
|
||||
mustMatchWhenDerived: false,
|
||||
storage: HostStorage,
|
||||
validate (value) {
|
||||
assert(typeof value === 'string' || Object.prototype.toString.call(value) === '[object RegExp]', 'Host should be a string or a RegExp')
|
||||
}
|
||||
}
|
||||
65
backend/node_modules/find-my-way/lib/strategies/accept-version.js
generated
vendored
Normal file
65
backend/node_modules/find-my-way/lib/strategies/accept-version.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
'use strict'
|
||||
|
||||
const assert = require('node:assert')
|
||||
|
||||
function SemVerStore () {
|
||||
if (!(this instanceof SemVerStore)) {
|
||||
return new SemVerStore()
|
||||
}
|
||||
|
||||
this.store = {}
|
||||
|
||||
this.maxMajor = 0
|
||||
this.maxMinors = {}
|
||||
this.maxPatches = {}
|
||||
}
|
||||
|
||||
SemVerStore.prototype.set = function (version, store) {
|
||||
if (typeof version !== 'string') {
|
||||
throw new TypeError('Version should be a string')
|
||||
}
|
||||
let [major, minor, patch] = version.split('.')
|
||||
|
||||
if (isNaN(major)) {
|
||||
throw new TypeError('Major version must be a numeric value')
|
||||
}
|
||||
|
||||
major = Number(major)
|
||||
minor = Number(minor) || 0
|
||||
patch = Number(patch) || 0
|
||||
|
||||
if (major >= this.maxMajor) {
|
||||
this.maxMajor = major
|
||||
this.store.x = store
|
||||
this.store['*'] = store
|
||||
this.store['x.x'] = store
|
||||
this.store['x.x.x'] = store
|
||||
}
|
||||
|
||||
if (minor >= (this.maxMinors[major] || 0)) {
|
||||
this.maxMinors[major] = minor
|
||||
this.store[`${major}.x`] = store
|
||||
this.store[`${major}.x.x`] = store
|
||||
}
|
||||
|
||||
if (patch >= (this.maxPatches[`${major}.${minor}`] || 0)) {
|
||||
this.maxPatches[`${major}.${minor}`] = patch
|
||||
this.store[`${major}.${minor}.x`] = store
|
||||
}
|
||||
|
||||
this.store[`${major}.${minor}.${patch}`] = store
|
||||
return this
|
||||
}
|
||||
|
||||
SemVerStore.prototype.get = function (version) {
|
||||
return this.store[version]
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'version',
|
||||
mustMatchWhenDerived: true,
|
||||
storage: SemVerStore,
|
||||
validate (value) {
|
||||
assert(typeof value === 'string', 'Version should be a string')
|
||||
}
|
||||
}
|
||||
14
backend/node_modules/find-my-way/lib/strategies/http-method.js
generated
vendored
Normal file
14
backend/node_modules/find-my-way/lib/strategies/http-method.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
name: '__fmw_internal_strategy_merged_tree_http_method__',
|
||||
storage: function () {
|
||||
const handlers = {}
|
||||
return {
|
||||
get: (type) => { return handlers[type] || null },
|
||||
set: (type, store) => { handlers[type] = store }
|
||||
}
|
||||
},
|
||||
deriveConstraint: /* istanbul ignore next */ (req) => req.method,
|
||||
mustMatchWhenDerived: true
|
||||
}
|
||||
Reference in New Issue
Block a user