feat: add manual file enhancement with development mode support
- Add manual enhance API endpoint (POST /api/enhance?site_id={site}) for triggering file enhancement
- Implement enhance button in JavaScript library status indicator (🔄 Enhance)
- Disable auto-enhancement in development mode to prevent live-reload conflicts
- Add dev mode parameter to SiteManager to control enhancement behavior
- Update API routing structure to support /api/enhance endpoint
- Include enhance button styling and user feedback (loading, success, error states)
- Button triggers file enhancement and page reload to show updated static files
Development workflow improvements:
- Content edits → Immediate editor preview (no unwanted page reloads)
- Manual enhance button → Intentional file updates + reload for testing
- Production mode maintains automatic enhancement on content changes
This resolves the live-reload conflict where automatic file enhancement
was causing unwanted page reloads during content editing in development.
This commit is contained in:
33
cmd/serve.go
33
cmd/serve.go
@@ -124,25 +124,30 @@ func runServe(cmd *cobra.Command, args []string) {
|
||||
router.HandleFunc("/health", api.HealthMiddleware())
|
||||
|
||||
// API routes
|
||||
apiRouter := router.PathPrefix("/api/content").Subrouter()
|
||||
apiRouter := router.PathPrefix("/api").Subrouter()
|
||||
|
||||
// Content endpoints matching the expected API contract
|
||||
apiRouter.HandleFunc("/bulk", contentHandler.GetBulkContent).Methods("GET")
|
||||
apiRouter.HandleFunc("/{id}", contentHandler.GetContent).Methods("GET")
|
||||
apiRouter.HandleFunc("/{id}", contentHandler.UpdateContent).Methods("PUT")
|
||||
apiRouter.HandleFunc("", contentHandler.GetAllContent).Methods("GET")
|
||||
apiRouter.HandleFunc("", contentHandler.CreateContent).Methods("POST")
|
||||
// Content endpoints
|
||||
contentRouter := apiRouter.PathPrefix("/content").Subrouter()
|
||||
contentRouter.HandleFunc("/bulk", contentHandler.GetBulkContent).Methods("GET")
|
||||
contentRouter.HandleFunc("/{id}", contentHandler.GetContent).Methods("GET")
|
||||
contentRouter.HandleFunc("/{id}", contentHandler.UpdateContent).Methods("PUT")
|
||||
contentRouter.HandleFunc("", contentHandler.GetAllContent).Methods("GET")
|
||||
contentRouter.HandleFunc("", contentHandler.CreateContent).Methods("POST")
|
||||
|
||||
// Version control endpoints
|
||||
apiRouter.HandleFunc("/{id}/versions", contentHandler.GetContentVersions).Methods("GET")
|
||||
apiRouter.HandleFunc("/{id}/rollback", contentHandler.RollbackContent).Methods("POST")
|
||||
contentRouter.HandleFunc("/{id}/versions", contentHandler.GetContentVersions).Methods("GET")
|
||||
contentRouter.HandleFunc("/{id}/rollback", contentHandler.RollbackContent).Methods("POST")
|
||||
|
||||
// Site enhancement endpoint
|
||||
apiRouter.HandleFunc("/enhance", contentHandler.EnhanceSite).Methods("POST")
|
||||
|
||||
// Handle CORS preflight requests explicitly
|
||||
apiRouter.HandleFunc("/{id}", api.CORSPreflightHandler).Methods("OPTIONS")
|
||||
apiRouter.HandleFunc("", api.CORSPreflightHandler).Methods("OPTIONS")
|
||||
apiRouter.HandleFunc("/bulk", api.CORSPreflightHandler).Methods("OPTIONS")
|
||||
apiRouter.HandleFunc("/{id}/versions", api.CORSPreflightHandler).Methods("OPTIONS")
|
||||
apiRouter.HandleFunc("/{id}/rollback", api.CORSPreflightHandler).Methods("OPTIONS")
|
||||
contentRouter.HandleFunc("/{id}", api.CORSPreflightHandler).Methods("OPTIONS")
|
||||
contentRouter.HandleFunc("", api.CORSPreflightHandler).Methods("OPTIONS")
|
||||
contentRouter.HandleFunc("/bulk", api.CORSPreflightHandler).Methods("OPTIONS")
|
||||
contentRouter.HandleFunc("/{id}/versions", api.CORSPreflightHandler).Methods("OPTIONS")
|
||||
contentRouter.HandleFunc("/{id}/rollback", api.CORSPreflightHandler).Methods("OPTIONS")
|
||||
apiRouter.HandleFunc("/enhance", api.CORSPreflightHandler).Methods("OPTIONS")
|
||||
|
||||
// Start server
|
||||
addr := fmt.Sprintf(":%d", port)
|
||||
|
||||
Reference in New Issue
Block a user