From b85b0c6260c33a129b2c72eec07f810f36928ca8 Mon Sep 17 00:00:00 2001 From: wood chen Date: Sun, 29 Sep 2024 15:19:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=92=8C=E6=A0=B9=E8=B7=AF=E5=BE=84=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E7=9A=84=E5=A4=84=E7=90=86=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BA=86=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/router.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/handler/router.go b/handler/router.go index b5fa9f6..387c55b 100644 --- a/handler/router.go +++ b/handler/router.go @@ -23,9 +23,14 @@ func Convert(c *fiber.Ctx) error { // 3. pass it to encoder, get the result, send it back // normal http request will start with / + // 检查路径是否以 "/" 开头 if !strings.HasPrefix(c.Path(), "/") { - _ = c.SendStatus(http.StatusBadRequest) - return nil + return c.SendStatus(http.StatusBadRequest) + } + + // 处理根路径请求 + if c.Path() == "/" { + return c.SendString("Welcome to WebP Server") } var ( @@ -64,12 +69,6 @@ func Convert(c *fiber.Ctx) error { // // - // 处理根路径请求 - if reqURI == "/" { - // 重定向到一个适当的页面或返回一个默认响应 - return c.SendString("Welcome to WebP Server") - } - if !isImageFile(filename) { log.Infof("Non-image file requested: %s, redirecting to original URL", reqURI) var redirectURL string