fix: SPA routing and prompts table handling

- Add clean URL routing: /dashboard -> dashboard.html, /settings -> settings.html
- Add EnsurePromptsTable for dev environments where prompts table may not exist
- Fix nav links to use clean URLs instead of .html paths

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-06-26 15:08:12 +08:00
parent f456cdb565
commit b7008afd29
4 changed files with 57 additions and 5 deletions
+18
View File
@@ -0,0 +1,18 @@
# 服务配置
SERVER_PORT=8080
SESSION_SECRET=your-random-secret-key
# 数据库(连接已有的远程 MySQL 实例)
DB_HOST=your-mysql-public-ip
DB_PORT=3306
DB_USER=your-db-user
DB_PASSWORD=your-db-password
DB_NAME=prompt_generator
# 认证
AUTH_PASSWORD=your-access-password
# LLM
LLM_API_BASE_URL=https://api.deepseek.com/v1
LLM_API_KEY=sk-xxx
LLM_MODEL_NAME=deepseek-chat
+2 -2
View File
@@ -176,8 +176,8 @@ Theme.init();
function renderNavbar(activePage) {
const pages = [
{ id: 'builder', label: '构建器', href: '/' },
{ id: 'dashboard', label: '复盘看板', href: '/dashboard.html' },
{ id: 'settings', label: '设置', href: '/settings.html' },
{ id: 'dashboard', label: '复盘看板', href: '/dashboard' },
{ id: 'settings', label: '设置', href: '/settings' },
];
const nav = document.createElement('nav');
+18
View File
@@ -109,6 +109,24 @@ func AutoMigrate() error {
return nil
}
// EnsurePromptsTable creates the prompts table if it doesn't exist (for dev environments)
func EnsurePromptsTable() {
_, err := DB.Exec(`CREATE TABLE IF NOT EXISTS prompts (
id bigint NOT NULL AUTO_INCREMENT,
session_id varchar(128) NOT NULL,
project_name varchar(255) NOT NULL DEFAULT '',
prompt text NOT NULL,
created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY idx_session_id (session_id),
KEY idx_project_name (project_name),
KEY idx_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`)
if err != nil {
log.Printf("Warning: failed to ensure prompts table: %v", err)
}
}
func SeedData() error {
// Check if system tags already exist
var count int
+19 -3
View File
@@ -38,12 +38,28 @@ func main() {
// Initialize handlers
handlers.Init(cfg)
// Ensure prompts table exists for dev environments
db.EnsurePromptsTable()
// Setup routes
mux := http.NewServeMux()
// Static files (frontend)
fs := http.FileServer(http.Dir("frontend"))
mux.Handle("/", fs)
// Static files with SPA-style routing for HTML pages
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
// Map clean URLs to .html files
switch path {
case "/dashboard":
http.ServeFile(w, r, "frontend/dashboard.html")
return
case "/settings":
http.ServeFile(w, r, "frontend/settings.html")
return
}
// Default file server
fs := http.FileServer(http.Dir("frontend"))
fs.ServeHTTP(w, r)
})
// Auth routes (no auth required)
mux.HandleFunc("POST /api/auth/login", handlers.Login)