mirror of https://github.com/hunshcn/gh-proxy
增加对自定义路由不为根路径的支持
parent
d3768b71d9
commit
0dd4fb3a25
|
@ -37,6 +37,10 @@ github release、archive以及项目文件的加速项目,支持clone,有Clo
|
|||
|
||||
`index.js`默认配置下clone走github.com.cnpmjs.org,项目文件会走jsDeliver,如需走worker,修改Config变量即可
|
||||
|
||||
`ASSET_URL`是静态资源的url(实际上就是现在显示出来的那个输入框单页面)
|
||||
|
||||
`PREFIX`是前缀,默认(根路径情况为"/"),如果自定义路由为example.com/gh/*,请将PREFIX改为 '/gh/',注意,少一个杠都会错!
|
||||
|
||||
## Python版本部署
|
||||
|
||||
### Docker部署
|
||||
|
|
8
index.js
8
index.js
|
@ -4,6 +4,8 @@
|
|||
* static files (404.html, sw.js, conf.js)
|
||||
*/
|
||||
const ASSET_URL = 'https://hunshcn.github.io/gh-proxy'
|
||||
// 前缀,如果自定义路由为example.com/gh/*,将PREFIX改为 '/gh/',注意,少一个杠都会错!
|
||||
const PREFIX = '/'
|
||||
// git使用cnpmjs镜像、分支文件使用jsDelivr镜像的开关,0为关闭,默认开启
|
||||
const Config = {
|
||||
jsdelivr: 1,
|
||||
|
@ -59,10 +61,10 @@ async function fetchHandler(e) {
|
|||
const urlObj = new URL(urlStr)
|
||||
let path = urlObj.searchParams.get('q')
|
||||
if (path) {
|
||||
return Response.redirect('https://' + urlObj.host + '/' + path, 301)
|
||||
return Response.redirect('https://' + urlObj.host + PREFIX + path, 301)
|
||||
}
|
||||
// cfworker 会把路径中的 `//` 合并成 `/`
|
||||
path = urlObj.href.substr(urlObj.origin.length + 1).replace(/^https?:\/+/, 'https://')
|
||||
path = urlObj.href.substr(urlObj.origin.length + PREFIX.length).replace(/^https?:\/+/, 'https://')
|
||||
const exp1 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:releases|archive)\/.*$/
|
||||
const exp2 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:blob)\/.*$/
|
||||
const exp3 = /^(?:https?:\/\/)?github\.com\/.+?\/.+?\/(?:info|git-upload-pack).*$/
|
||||
|
@ -102,8 +104,6 @@ function httpHandler(req, pathname) {
|
|||
|
||||
const reqHdrNew = new Headers(reqHdrRaw)
|
||||
|
||||
const refer = reqHdrNew.get('referer')
|
||||
|
||||
let urlStr = pathname
|
||||
if (urlStr.startsWith('github')) {
|
||||
urlStr = 'https://' + urlStr
|
||||
|
|
Loading…
Reference in New Issue