1 Star 0 Fork 0

wannabe-9/UnblockNeteaseMusic

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
endpoint.worker.js 735 Bytes
一键复制 编辑 原始数据 按行查看 历史
nondanee 提交于 2020-05-27 01:25 . provide serverless endpoint script
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const pattern = /^\/package\/([0-9a-zA-Z_\-=]+)\/(\w+\.\w+)$/
const handleRequest = async request => {
const notFound = new Response(null, { status: 404 })
const path = new URL(request.url).pathname
const [matched, base64Url, fileName] = pattern.exec(path || '') || []
if (!matched) return notFound
let url = base64Url.replace(/-/g, '+').replace(/_/g, '/')
try { url = new URL(atob(url)) } catch(_) { url = null }
if (!url) return notFound
const headers = new Headers(request.headers)
headers.set('host', url.host)
headers.delete('cookie')
const { method, body } = request
return fetch(url, { method, headers, body })
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wannabe-9/UnblockNeteaseMusic.git
git@gitee.com:wannabe-9/UnblockNeteaseMusic.git
wannabe-9
UnblockNeteaseMusic
UnblockNeteaseMusic
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385