diff --git a/internal/server/router/router.go b/internal/server/router/router.go index add8cc4..e937761 100644 --- a/internal/server/router/router.go +++ b/internal/server/router/router.go @@ -122,6 +122,14 @@ type spaHandler struct { func (h *spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { path := r.URL.Path + // API 请求不应该返回 SPA 页面 + if len(path) >= 4 && path[:4] == "/api" { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusNotFound) + w.Write([]byte(`{"code":404,"message":"Not Found"}`)) + return + } + // 尝试打开请求的文件 f, err := h.fs.Open(path) if err != nil { diff --git a/web/src/api/index.ts b/web/src/api/index.ts index cd02924..a244004 100644 --- a/web/src/api/index.ts +++ b/web/src/api/index.ts @@ -36,7 +36,7 @@ export const stopClientPlugin = (clientId: string, pluginName: string, ruleName: export const restartClientPlugin = (clientId: string, pluginName: string, ruleName: string) => post(`/client/${clientId}/plugin/${pluginName}/restart`, { rule_name: ruleName }) export const deleteClientPlugin = (clientId: string, pluginName: string) => - del(`/client/${clientId}/plugin/${pluginName}/delete`) + post(`/client/${clientId}/plugin/${pluginName}/delete`) export const updateClientPluginConfigWithRestart = (clientId: string, pluginName: string, ruleName: string, config: Record, restart: boolean) => post(`/client/${clientId}/plugin/${pluginName}/config`, { rule_name: ruleName, config, restart })