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:
@@ -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
|
||||||
@@ -176,8 +176,8 @@ Theme.init();
|
|||||||
function renderNavbar(activePage) {
|
function renderNavbar(activePage) {
|
||||||
const pages = [
|
const pages = [
|
||||||
{ id: 'builder', label: '构建器', href: '/' },
|
{ id: 'builder', label: '构建器', href: '/' },
|
||||||
{ id: 'dashboard', label: '复盘看板', href: '/dashboard.html' },
|
{ id: 'dashboard', label: '复盘看板', href: '/dashboard' },
|
||||||
{ id: 'settings', label: '设置', href: '/settings.html' },
|
{ id: 'settings', label: '设置', href: '/settings' },
|
||||||
];
|
];
|
||||||
|
|
||||||
const nav = document.createElement('nav');
|
const nav = document.createElement('nav');
|
||||||
|
|||||||
@@ -109,6 +109,24 @@ func AutoMigrate() error {
|
|||||||
return nil
|
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 {
|
func SeedData() error {
|
||||||
// Check if system tags already exist
|
// Check if system tags already exist
|
||||||
var count int
|
var count int
|
||||||
|
|||||||
@@ -38,12 +38,28 @@ func main() {
|
|||||||
// Initialize handlers
|
// Initialize handlers
|
||||||
handlers.Init(cfg)
|
handlers.Init(cfg)
|
||||||
|
|
||||||
|
// Ensure prompts table exists for dev environments
|
||||||
|
db.EnsurePromptsTable()
|
||||||
|
|
||||||
// Setup routes
|
// Setup routes
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
// Static files (frontend)
|
// 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 := http.FileServer(http.Dir("frontend"))
|
||||||
mux.Handle("/", fs)
|
fs.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
|
||||||
// Auth routes (no auth required)
|
// Auth routes (no auth required)
|
||||||
mux.HandleFunc("POST /api/auth/login", handlers.Login)
|
mux.HandleFunc("POST /api/auth/login", handlers.Login)
|
||||||
|
|||||||
Reference in New Issue
Block a user