fix: make vercel go entrypoint internal-safe

This commit is contained in:
CJACK
2026-02-16 18:04:12 +08:00
parent 63ee2e41c2
commit 0913c477a6
4 changed files with 33 additions and 4 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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)
}

11
app/handler.go Normal file
View File

@@ -0,0 +1,11 @@
package app
import (
"net/http"
"ds2api/internal/server"
)
func NewHandler() http.Handler {
return server.NewApp().Router
}