feat: worker白名单

pull/85/head
hunsh 2022-07-06 22:01:23 +08:00 committed by hunshcn
parent d9fd3fad73
commit f420bd2e95
1 changed files with 12 additions and 0 deletions

View File

@ -11,6 +11,8 @@ const Config = {
jsdelivr: 0
}
const whiteList = [] // 白名单路径里面有包含字符的才会通过e.g. ['/username/']
/** @type {RequestInit} */
const PREFLIGHT_INIT = {
status: 204,
@ -117,6 +119,16 @@ function httpHandler(req, pathname) {
const reqHdrNew = new Headers(reqHdrRaw)
let urlStr = pathname
let flag = false
for (let i of whiteList) {
if (urlStr.includes(i)) {
flag = true
break
}
}
if (!flag) {
return new Response("blocked", {status: 403})
}
if (urlStr.startsWith('github')) {
urlStr = 'https://' + urlStr
}