mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-01 23:15:27 +08:00
fix: make vercel go entrypoint internal-safe
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
11
app/handler.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"ds2api/internal/server"
|
||||
)
|
||||
|
||||
func NewHandler() http.Handler {
|
||||
return server.NewApp().Router
|
||||
}
|
||||
Reference in New Issue
Block a user