From fd4f7708babfd1aee38b573b6b29271af8f295cf Mon Sep 17 00:00:00 2001 From: Blizzard Date: Thu, 1 Oct 2026 14:14:54 +0800 Subject: [PATCH 1/2] Point mini program API to production domain --- pets-fe/utils/config.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pets-fe/utils/config.js b/pets-fe/utils/config.js index dd901fc..ac9203d 100644 --- a/pets-fe/utils/config.js +++ b/pets-fe/utils/config.js @@ -1,4 +1,3 @@ -const baseURL = 'http://192.168.100.3:9090/api' -//const baseURL = 'https://pet.sundynix.cn' +const baseURL = 'https://pet.sundynix.cn/api' module.exports = { baseURL}; From 5688db4d638b28dd34ba2a30158e6cf2e298e4d2 Mon Sep 17 00:00:00 2001 From: Blizzard Date: Thu, 1 Oct 2026 14:23:50 +0800 Subject: [PATCH 2/2] Serve embedded admin assets from root --- pets-be/internal/admin/embed.go | 6 +++++- pets-be/internal/admin/embed_test.go | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pets-be/internal/admin/embed.go b/pets-be/internal/admin/embed.go index 79a2caa..5ff22b3 100644 --- a/pets-be/internal/admin/embed.go +++ b/pets-be/internal/admin/embed.go @@ -31,6 +31,10 @@ func Register(r *gin.Engine) { fileServer.ServeHTTP(c.Writer, c.Request) return } + if strings.HasPrefix(reqPath, "assets/") { + c.Status(http.StatusNotFound) + return + } } // SPA fallback data, err := fs.ReadFile(sub, "index.html") @@ -43,7 +47,7 @@ func Register(r *gin.Engine) { r.GET("/", handler) r.NoRoute(func(c *gin.Context) { - if c.Request.Method != http.MethodGet || strings.HasPrefix(c.Request.URL.Path, "/api/") || c.Request.URL.Path == "/api" || strings.HasPrefix(c.Request.URL.Path, "/assets/") { + if (c.Request.Method != http.MethodGet && c.Request.Method != http.MethodHead) || strings.HasPrefix(c.Request.URL.Path, "/api/") || c.Request.URL.Path == "/api" { c.Status(http.StatusNotFound) return } diff --git a/pets-be/internal/admin/embed_test.go b/pets-be/internal/admin/embed_test.go index 93bfd23..1be2005 100644 --- a/pets-be/internal/admin/embed_test.go +++ b/pets-be/internal/admin/embed_test.go @@ -1,6 +1,7 @@ package admin import ( + "io/fs" "net/http" "net/http/httptest" "strings" @@ -16,6 +17,20 @@ func TestAdminAtRootAndAPIRoutes(t *testing.T) { r := gin.New() httpapi.New(nil, nil, &config.Config{}).Register(r) Register(r) + assets, err := fs.ReadDir(distFS, "dist/assets") + if err != nil { + t.Fatal(err) + } + var script string + for _, asset := range assets { + if strings.HasSuffix(asset.Name(), ".js") { + script = "/assets/" + asset.Name() + break + } + } + if script == "" { + t.Fatal("admin bundle has no JavaScript asset") + } for _, tc := range []struct { path string @@ -23,6 +38,8 @@ func TestAdminAtRootAndAPIRoutes(t *testing.T) { body string }{ {path: "/", status: http.StatusOK, body: "
"}, + {path: script, status: http.StatusOK}, + {path: "/favicon.svg", status: http.StatusOK}, {path: "/api/ping", status: http.StatusOK, body: "pong"}, {path: "/api/missing", status: http.StatusNotFound}, {path: "/assets/missing.js", status: http.StatusNotFound},