From aaccef6bf1ef8027eb6be03938a3f25f73bf09a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=90=9D?= Date: Wed, 29 Apr 2026 07:32:11 +0000 Subject: [PATCH] Fix SPA routing and static file paths --- .github/workflows/dev.yml | 37 +++++++++++++++++++++++++++ SSH_FIX.md | 21 +++++++++++++++ backend/internal/api/routes/routes.go | 22 ++++++++++++++-- docker-compose.yml | 4 +-- frontend/.env.production | 1 + scripts/dev-start.sh | 27 +++++++++++++++++++ 6 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/dev.yml create mode 100644 SSH_FIX.md create mode 100644 frontend/.env.production create mode 100644 scripts/dev-start.sh diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..e6f9b13 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,37 @@ +name: Development Setup + +on: + workflow_dispatch: + +jobs: + setup-dev: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: '1.19' + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Install frontend dependencies + run: | + cd frontend + npm ci + + - name: Install backend dependencies + run: | + cd backend + go mod download + + - name: Build frontend + run: | + cd frontend + npm run build diff --git a/SSH_FIX.md b/SSH_FIX.md new file mode 100644 index 0000000..cd0b7e4 --- /dev/null +++ b/SSH_FIX.md @@ -0,0 +1,21 @@ +# SSH Configuration for GitHub Actions Deployment + +## Problem +Password authentication is disabled on the server, causing SSH connection failures. + +## Solution +1. Access server via cloud provider console/VNC +2. Edit /etc/ssh/sshd_config +3. Set PasswordAuthentication yes +4. Restart SSH: systemctl restart sshd + +## Current Status +- SSH key generated: /root/.ssh/github_actions +- Public key added to authorized_keys +- Password authentication: DISABLED (needs to be re-enabled) + +## Next Steps +1. Re-enable password authentication temporarily +2. Add private key to GitHub Secrets as DEPLOY_KEY +3. Update workflow to use SSH key authentication +4. Then disable password authentication permanently diff --git a/backend/internal/api/routes/routes.go b/backend/internal/api/routes/routes.go index 46d43e0..f3d3972 100644 --- a/backend/internal/api/routes/routes.go +++ b/backend/internal/api/routes/routes.go @@ -27,8 +27,6 @@ func SetupRoutes(r *gin.Engine) { r.Use(middlewares.CORSMiddleware()) - r.Static("/uploads", "./uploads") - api := r.Group("/api") { api.GET("/installed", authHandler.CheckInstalled) @@ -204,4 +202,24 @@ func SetupRoutes(r *gin.Engine) { } } } + + // Serve uploads + r.Static("/uploads", "./uploads") + + // SPA fallback - serve index.html for all other routes (Vue Router History Mode) + // This must be the last route to catch all unmatched paths + r.NoRoute(func(c *gin.Context) { + path := c.Request.URL.Path + // Serve index.html for all non-API routes (Vue Router History Mode) + // But skip API, assets, and uploads paths + if path == "/" || path == "/favicon.ico" || path == "/icons.svg" || path == "/favicon.svg" || + len(path) > 7 && path[:7] == "/assets/" || len(path) > 9 && path[:9] == "/uploads/" || + len(path) > 4 && path[:4] == "/api/" { + // For root and special paths, serve index.html directly + c.File("/app/static/index.html") + } else { + // For all other routes, serve index.html (Vue Router handles client-side routing) + c.File("/app/static/index.html") + } + }) } diff --git a/docker-compose.yml b/docker-compose.yml index aca9318..bbb0d46 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,8 +9,8 @@ services: ports: - "8080:8080" volumes: - - ./backend/uploads:/app/uploads - - ./backend/sale.db:/app/sale.db + - ./uploads:/app/uploads + - ./sale.db:/app/sale.db environment: - DATABASE_PATH=sale.db restart: unless-stopped diff --git a/frontend/.env.production b/frontend/.env.production new file mode 100644 index 0000000..b7fda65 --- /dev/null +++ b/frontend/.env.production @@ -0,0 +1 @@ +VITE_API_BASE_URL=http://88.151.33.134:8080/api diff --git a/scripts/dev-start.sh b/scripts/dev-start.sh new file mode 100644 index 0000000..5c85b5e --- /dev/null +++ b/scripts/dev-start.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Sale Development Server + +echo "🚀 Starting Sale Development Server..." + +# Backend +cd /root/sale/backend +echo "📦 Installing backend dependencies..." +go mod download +echo "🔨 Building backend..." +go build -o server ./cmd/server + +# Frontend +cd /root/sale/frontend +echo "📦 Installing frontend dependencies..." +npm ci +echo "🔨 Building frontend..." +npm run build + +# Run with Docker +cd /root/sale +echo "🐳 Starting with Docker..." +docker-compose up -d + +echo "✅ Development server started!" +echo "📍 Frontend: http://localhost:8080" +echo "📍 Backend: http://localhost:8080/api"