mirror of https://github.com/hunshcn/gh-proxy
feat: worker白名单
parent
d9fd3fad73
commit
f420bd2e95
12
index.js
12
index.js
|
@ -11,6 +11,8 @@ const Config = {
|
||||||
jsdelivr: 0
|
jsdelivr: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const whiteList = [] // 白名单,路径里面有包含字符的才会通过,e.g. ['/username/']
|
||||||
|
|
||||||
/** @type {RequestInit} */
|
/** @type {RequestInit} */
|
||||||
const PREFLIGHT_INIT = {
|
const PREFLIGHT_INIT = {
|
||||||
status: 204,
|
status: 204,
|
||||||
|
@ -117,6 +119,16 @@ function httpHandler(req, pathname) {
|
||||||
const reqHdrNew = new Headers(reqHdrRaw)
|
const reqHdrNew = new Headers(reqHdrRaw)
|
||||||
|
|
||||||
let urlStr = pathname
|
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')) {
|
if (urlStr.startsWith('github')) {
|
||||||
urlStr = 'https://' + urlStr
|
urlStr = 'https://' + urlStr
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue