From 0913c477a6e1003897eb7fddbdad44eccf169b6e Mon Sep 17 00:00:00 2001 From: CJACK Date: Mon, 16 Feb 2026 18:04:12 +0800 Subject: [PATCH] fix: make vercel go entrypoint internal-safe --- DEPLOY.en.md | 9 +++++++++ DEPLOY.md | 9 +++++++++ api/index.go | 8 ++++---- app/handler.go | 11 +++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 app/handler.go diff --git a/DEPLOY.en.md b/DEPLOY.en.md index bf09b31..f05cd3c 100644 --- a/DEPLOY.en.md +++ b/DEPLOY.en.md @@ -113,6 +113,15 @@ How to fix: 4. Ensure `go.mod` uses a supported version (this repo uses `go 1.24`) 5. Redeploy (preferably with cache cleared) +Another common root cause (Go monorepo + `internal/`): + +```text +... use of internal package ds2api/internal/server not allowed +``` + +This usually happens when the Vercel Go entrypoint imports `internal/...` directly. +This repo now avoids that by using a public bridge package: `api/index.go` -> `ds2api/app` -> `internal/server`. + ## 4. Reverse Proxy (Nginx) Disable buffering for SSE: diff --git a/DEPLOY.md b/DEPLOY.md index fa75a36..72ddfd9 100644 --- a/DEPLOY.md +++ b/DEPLOY.md @@ -112,6 +112,15 @@ Error: Command failed: go build -ldflags -s -w -o .../bootstrap .../main__vc__go 4. 确认仓库 `go.mod` 为受支持版本(当前为 `go 1.24`) 5. 重新部署(建议 `Redeploy` 并清缓存) +另一个常见根因(Go 单仓 + `internal/`): + +```text +... use of internal package ds2api/internal/server not allowed +``` + +这通常发生在 Vercel Go 入口文件直接 `import internal/...`。 +当前仓库已通过公开桥接包 `app` 解决:`api/index.go` -> `ds2api/app` -> `internal/server`。 + ## 4. 反向代理(Nginx) 如果在 Nginx 后挂载,建议关闭缓冲以保证 SSE: diff --git a/api/index.go b/api/index.go index 326e83f..147ce32 100644 --- a/api/index.go +++ b/api/index.go @@ -4,17 +4,17 @@ import ( "net/http" "sync" - "ds2api/internal/server" + "ds2api/app" ) var ( once sync.Once - app *server.App + h http.Handler ) func Handler(w http.ResponseWriter, r *http.Request) { once.Do(func() { - app = server.NewApp() + h = app.NewHandler() }) - app.Router.ServeHTTP(w, r) + h.ServeHTTP(w, r) } diff --git a/app/handler.go b/app/handler.go new file mode 100644 index 0000000..a8979fd --- /dev/null +++ b/app/handler.go @@ -0,0 +1,11 @@ +package app + +import ( + "net/http" + + "ds2api/internal/server" +) + +func NewHandler() http.Handler { + return server.NewApp().Router +}