fix(web): bypass frontend for alpha search

This commit is contained in:
Zven
2026-07-13 12:06:51 +08:00
parent a1930ea6f2
commit b0fa2b352f
2 changed files with 27 additions and 0 deletions
+1
View File
@@ -308,6 +308,7 @@ func shouldBypassEmbeddedFrontend(path string) bool {
trimmed == "/health" ||
trimmed == "/responses" ||
strings.HasPrefix(trimmed, "/responses/") ||
trimmed == "/alpha/search" ||
strings.HasPrefix(trimmed, "/images/")
}
+26
View File
@@ -507,6 +507,32 @@ func TestFrontendServer_Middleware(t *testing.T) {
assert.JSONEq(t, `{"ok":true}`, w.Body.String())
})
t.Run("skips_alpha_search_post_route", func(t *testing.T) {
provider := &mockSettingsProvider{
settings: map[string]string{"test": "value"},
}
server, err := NewFrontendServer(provider)
require.NoError(t, err)
router := gin.New()
router.Use(server.Middleware())
nextCalled := false
router.POST("/alpha/search", func(c *gin.Context) {
nextCalled = true
c.JSON(http.StatusOK, gin.H{"ok": true})
})
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodPost, "/alpha/search", strings.NewReader(`{"model":"gpt-5.6-sol"}`))
req.Header.Set("Content-Type", "application/json")
router.ServeHTTP(w, req)
assert.True(t, nextCalled, "next handler should be called for alpha search API route")
assert.Equal(t, http.StatusOK, w.Code)
assert.JSONEq(t, `{"ok":true}`, w.Body.String())
})
t.Run("serves_index_for_spa_routes", func(t *testing.T) {
provider := &mockSettingsProvider{
settings: map[string]string{"test": "value"},