Fix SPA routing and static file paths

This commit is contained in:
小萝
2026-04-29 07:32:11 +00:00
parent 826daabfa8
commit aaccef6bf1
6 changed files with 108 additions and 4 deletions
+37
View File
@@ -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
+21
View File
@@ -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
+20 -2
View File
@@ -27,8 +27,6 @@ func SetupRoutes(r *gin.Engine) {
r.Use(middlewares.CORSMiddleware()) r.Use(middlewares.CORSMiddleware())
r.Static("/uploads", "./uploads")
api := r.Group("/api") api := r.Group("/api")
{ {
api.GET("/installed", authHandler.CheckInstalled) 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")
}
})
} }
+2 -2
View File
@@ -9,8 +9,8 @@ services:
ports: ports:
- "8080:8080" - "8080:8080"
volumes: volumes:
- ./backend/uploads:/app/uploads - ./uploads:/app/uploads
- ./backend/sale.db:/app/sale.db - ./sale.db:/app/sale.db
environment: environment:
- DATABASE_PATH=sale.db - DATABASE_PATH=sale.db
restart: unless-stopped restart: unless-stopped
+1
View File
@@ -0,0 +1 @@
VITE_API_BASE_URL=http://88.151.33.134:8080/api
+27
View File
@@ -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"