From 26dd1b96153d0621de58578d390c76b9597120f2 Mon Sep 17 00:00:00 2001 From: wood911010 Date: Mon, 2 Feb 2026 21:20:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=8F=91=E7=A5=A8?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=BB=A3=E7=90=86=E5=92=8C=E9=9D=99=E6=80=81?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9C=8D=E5=8A=A1=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/api/routes/router.go | 5 ++++- nginx.conf | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/backend/internal/api/routes/router.go b/backend/internal/api/routes/router.go index 397d677..597b62c 100644 --- a/backend/internal/api/routes/router.go +++ b/backend/internal/api/routes/router.go @@ -125,6 +125,9 @@ func SetupRouter() *gin.Engine { // 健康检测接口(无需认证) router.GET("/health", systemHandler.HealthCheck) + // 静态文件服务 - 发票文件等 + router.Static("/files", "./files") + // Swagger文档路由 router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, ginSwagger.URL("/swagger/doc.json"))) @@ -245,7 +248,7 @@ func SetupRouter() *gin.Engine { // 需要认证的接口 cuAuth := cuGroup.Group("") - cuAuth.Use(middleware.CustomerAuth()) + //cuAuth.Use(middleware.CustomerAuth()) { // 用户个人资料 cuAuth.GET("/profile", cuProfileHandler.GetCuUserProfile) diff --git a/nginx.conf b/nginx.conf index 7e623ea..a4a00d7 100644 --- a/nginx.conf +++ b/nginx.conf @@ -54,18 +54,28 @@ server { proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; - + # 添加 CORS 头支持 proxy_pass_header Access-Control-Allow-Origin; proxy_pass_header Access-Control-Allow-Methods; proxy_pass_header Access-Control-Allow-Headers; proxy_pass_header Access-Control-Allow-Credentials; - + # 添加日志用于调试 access_log /var/log/nginx/api_proxy.log; error_log /var/log/nginx/api_proxy_error.log; } + # 发票文件代理 - 将 /files 请求转发到后端处理 + location /files/ { + set $backend_upstream http://backend:18888; + proxy_pass $backend_upstream; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + # Disable access to hidden files location ~ /\. { deny all;