From 1f3c4adc9645007ae028dc21a867b10affc962d3 Mon Sep 17 00:00:00 2001 From: iriver Date: Tue, 15 Jul 2025 23:22:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DJWT=E5=AF=86=E9=92=A5?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=92=8C=E5=AE=B9=E5=99=A8=E5=86=85=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复YAML配置文件字段格式错误(大写->小写) - 修复JWT密钥未正确识别的问题 - 修复容器内配置文件路径问题,使用绝对路径/etc/photography-api.yaml - 修复迁移工具配置文件路径 - 修复Dockerfile工作目录设置 解决了'field auth.access_secret is not set'的配置错误 --- backend/Dockerfile | 3 ++ backend/cmd/api/main.go | 2 +- backend/cmd/migrate/main.go | 4 +-- backend/etc/photography-api.yaml | 50 ++++++++++++++++---------------- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 6c22cfc..83b2c2d 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -58,6 +58,9 @@ COPY --from=builder /app/etc /etc # 设置时区 ENV TZ=Asia/Shanghai +# 创建工作目录 +WORKDIR /app + # 创建非root用户 (在scratch镜像中需要手动创建) USER 65534:65534 diff --git a/backend/cmd/api/main.go b/backend/cmd/api/main.go index 6f7d9c8..06c7eb3 100644 --- a/backend/cmd/api/main.go +++ b/backend/cmd/api/main.go @@ -13,7 +13,7 @@ import ( "github.com/zeromicro/go-zero/rest" ) -var configFile = flag.String("f", "etc/photography-api.yaml", "the config file") +var configFile = flag.String("f", "/etc/photography-api.yaml", "the config file") func main() { flag.Parse() diff --git a/backend/cmd/migrate/main.go b/backend/cmd/migrate/main.go index 1a3c669..b706e48 100644 --- a/backend/cmd/migrate/main.go +++ b/backend/cmd/migrate/main.go @@ -16,7 +16,7 @@ import ( func main() { // 命令行参数 var ( - configFile = flag.String("f", "etc/photographyapi-api.yaml", "配置文件路径") + configFile = flag.String("f", "/etc/photography-api.yaml", "配置文件路径") command = flag.String("c", "status", "迁移命令: up, down, status, reset, migrate") steps = flag.Int("s", 0, "步数(用于 down 和 migrate 命令)") version = flag.String("v", "", "迁移版本(用于特定版本操作)") @@ -142,7 +142,7 @@ func showHelp() { fmt.Println(" go run cmd/migrate/main.go [选项] [参数]") fmt.Println() fmt.Println("选项:") - fmt.Println(" -f string 配置文件路径 (默认: etc/photographyapi-api.yaml)") + fmt.Println(" -f string 配置文件路径 (默认: /etc/photography-api.yaml)") fmt.Println(" -c string 迁移命令 (默认: status)") fmt.Println(" -s int 步数,用于 down 和 migrate 命令") fmt.Println(" -v string 迁移版本,用于特定版本操作") diff --git a/backend/etc/photography-api.yaml b/backend/etc/photography-api.yaml index c939fc3..c94ba4c 100644 --- a/backend/etc/photography-api.yaml +++ b/backend/etc/photography-api.yaml @@ -3,41 +3,41 @@ Host: 0.0.0.0 Port: 8080 # 数据库配置 -Database: - Driver: sqlite - FilePath: data/photography.db - Host: localhost - Port: 5432 - Database: photography - Username: postgres - Password: "" - Charset: utf8mb4 - SSLMode: disable - MaxOpenConns: 100 - MaxIdleConns: 10 +database: + driver: sqlite + file_path: data/photography.db + host: localhost + port: 5432 + database: photography + username: postgres + password: "" + charset: utf8mb4 + ssl_mode: disable + max_open_conns: 100 + max_idle_conns: 10 # 认证配置 -Auth: - AccessSecret: photography-secret-key-2024 - AccessExpire: 86400 +auth: + access_secret: photography-secret-key-2024 + access_expire: 86400 # 文件上传配置 -FileUpload: - MaxSize: 10485760 # 10MB - UploadDir: uploads - AllowedTypes: +file_upload: + max_size: 10485760 # 10MB + upload_dir: uploads + allowed_types: - image/jpeg - image/png - image/gif - image/webp # 中间件配置 -Middleware: - EnableCORS: true - EnableLogger: true - EnableErrorHandle: true - CORSOrigins: +middleware: + enable_cors: true + enable_logger: true + enable_error_handle: true + cors_origins: - http://localhost:3000 - http://localhost:3001 - http://localhost:5173 - LogLevel: info + log_level: info