diff --git a/Dockerfile b/Dockerfile index bb33044..b0fa867 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ -# 使用官方 Go 基础镜像,这里可以指定 Go 版本 FROM golang:1.22-alpine AS builder # 设置工作目录 @@ -27,4 +26,4 @@ COPY --from=builder /app/main . EXPOSE 80 # 运行可执行文件 -CMD ["./main"] +ENTRYPOINT ["./main"] diff --git a/README.md b/README.md index 27bad6d..3d1007f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,10 @@ A simple Go proxy for GitHub API, but MUCH lighter. Ported & modified from [huns ### Docker ```bash +# 直接运行,只允许代理 GitHub 链接 docker run -d -p 80:80 --name gh-proxy-go anotia/gh-proxy-go +# 允许代理任意链接 +docker run -d -p 80:80 --name gh-proxy-go anotia/gh-proxy-go --allow-any-url ``` ### 命令行运行 @@ -24,4 +27,7 @@ docker run -d -p 80:80 --name gh-proxy-go anotia/gh-proxy-go # 修改端口 / 地址 ./gh-proxy-go --port 8080 --host 127.0.0.1 + +# 允许代理任意链接 +./gh-proxy-go --allow-any-url ``` diff --git a/index.html b/index.html index 1723063..b73fe45 100644 --- a/index.html +++ b/index.html @@ -128,9 +128,7 @@

GitHub 文件加速

@@ -147,7 +145,8 @@

GitHub 文件加速

项目使用 Go 编写,开源于 GitHub,改编自 hunshcn/gh-proxy + href="https://github.com/AnotiaWang/gh-proxy-go">GitHub,改编自 hunshcn/gh-proxy

diff --git a/main.go b/main.go index 5ac13e7..9ab75cd 100644 --- a/main.go +++ b/main.go @@ -20,13 +20,14 @@ var ( jsdelivr = 0 // whiteList = []string{} // blackList = []string{} - passList = []string{} - exp1 = regexp.MustCompile(`^(?:https?://)?github\.com/(?P.+?)/(?P.+?)/(?:releases|archive)/.*$`) - exp2 = regexp.MustCompile(`^(?:https?://)?github\.com/(?P.+?)/(?P.+?)/(?:blob|raw)/.*$`) - exp3 = regexp.MustCompile(`^(?:https?://)?github\.com/(?P.+?)/(?P.+?)/(?:info|git-).*$`) - exp4 = regexp.MustCompile(`^(?:https?://)?raw\.(?:githubusercontent|github)\.com/(?P.+?)/(?P.+?)/.+?/.+$`) - exp5 = regexp.MustCompile(`^(?:https?://)?gist\.(?:githubusercontent|github)\.com/(?P.+?)/.+?/.+$`) - exp6 = regexp.MustCompile(`(\.com/.*?/.+?)/(.+?/)`) + passList = []string{} + exp1 = regexp.MustCompile(`^(?:https?://)?github\.com/(?P.+?)/(?P.+?)/(?:releases|archive)/.*$`) + exp2 = regexp.MustCompile(`^(?:https?://)?github\.com/(?P.+?)/(?P.+?)/(?:blob|raw)/.*$`) + exp3 = regexp.MustCompile(`^(?:https?://)?github\.com/(?P.+?)/(?P.+?)/(?:info|git-).*$`) + exp4 = regexp.MustCompile(`^(?:https?://)?raw\.(?:githubusercontent|github)\.com/(?P.+?)/(?P.+?)/.+?/.+$`) + exp5 = regexp.MustCompile(`^(?:https?://)?gist\.(?:githubusercontent|github)\.com/(?P.+?)/.+?/.+$`) + exp6 = regexp.MustCompile(`(\.com/.*?/.+?)/(.+?/)`) + allowAnyUrl bool ) func main() { @@ -35,6 +36,7 @@ func main() { flag.StringVar(&host, "host", "0.0.0.0", "Host address") flag.StringVar(&port, "port", "80", "Port number") + flag.BoolVar(&allowAnyUrl, "allow-any-url", false, "Do not check if the URL is a GitHub URL") flag.Parse() hostRegExp := regexp.MustCompile(`^\d+\.\d+\.\d+\.\d+$`) @@ -80,6 +82,11 @@ func main() { handler(c, path) }) + if allowAnyUrl { + log.Println("Mode: Allow any URL") + } else { + log.Println("Mode: GitHub URL only") + } log.Println("Starting server at " + host + ":" + port) err := router.Run(host + ":" + port) @@ -107,7 +114,7 @@ func handler(c *gin.Context, u string) { break } } - } else { + } else if !allowAnyUrl { c.String(http.StatusForbidden, "Invalid input.") return }