fix: disable auto-enhancement in development mode to prevent live-reload loops
- Add dev_mode parameter to SiteManager constructor - Modify IsAutoEnhanceEnabled() to return false when dev_mode is true - Update serve.go to pass dev_mode flag to SiteManager - Add ForceEnhanceEnabled() method for testing production behavior in development - Update documentation to explain development vs production mode behavior This fixes the development workflow where content updates would trigger file modifications that caused unwanted page reloads in live-server. Development mode: Content saved to database only, editor loads dynamically Production mode: Content saved + files enhanced for immediate static deployment
This commit is contained in:
18
COMMANDS.md
18
COMMANDS.md
@@ -104,9 +104,23 @@ When running `insertr serve`, the server automatically:
|
|||||||
- **Auto-updates files** when content changes via API
|
- **Auto-updates files** when content changes via API
|
||||||
- **Creates backups** of original files (if enabled)
|
- **Creates backups** of original files (if enabled)
|
||||||
|
|
||||||
**Live Enhancement Process:**
|
**Development vs Production Behavior:**
|
||||||
|
|
||||||
|
**Development Mode** (`--dev-mode`):
|
||||||
|
- ✅ Content changes saved to database
|
||||||
|
- ❌ File enhancement **disabled** (prevents live-reload loops)
|
||||||
|
- ✅ Editor loads content dynamically from API
|
||||||
|
- ✅ Perfect for `just dev` workflow
|
||||||
|
|
||||||
|
**Production Mode** (no `--dev-mode`):
|
||||||
|
- ✅ Content changes saved to database
|
||||||
|
- ✅ File enhancement **enabled**
|
||||||
|
- ✅ Static files updated immediately
|
||||||
|
- ✅ Changes live instantly
|
||||||
|
|
||||||
|
**Live Enhancement Process (Production):**
|
||||||
1. Content updated via API → Database updated
|
1. Content updated via API → Database updated
|
||||||
2. If site has `auto_enhance: true` → File enhancement triggered
|
2. If site has `auto_enhance: true` AND not in dev mode → File enhancement triggered
|
||||||
3. Static files updated in-place → Changes immediately live
|
3. Static files updated in-place → Changes immediately live
|
||||||
|
|
||||||
### API Endpoints
|
### API Endpoints
|
||||||
|
|||||||
25
README.md
25
README.md
@@ -436,14 +436,33 @@ server:
|
|||||||
backup_originals: true
|
backup_originals: true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### **Development vs Production Modes**
|
||||||
|
|
||||||
|
**Development Mode** (recommended for development):
|
||||||
|
```bash
|
||||||
|
# Development: Content updates save to database only
|
||||||
|
# NO file enhancement to prevent live-reload loops
|
||||||
|
./insertr serve --dev-mode
|
||||||
|
just dev # Uses dev mode automatically
|
||||||
|
```
|
||||||
|
|
||||||
|
**Production Mode** (for deployment):
|
||||||
|
```bash
|
||||||
|
# Production: Content updates trigger immediate file enhancement
|
||||||
|
./insertr serve # No --dev-mode flag
|
||||||
|
```
|
||||||
|
|
||||||
### **Quick Start**
|
### **Quick Start**
|
||||||
```bash
|
```bash
|
||||||
# 1. Configure sites in insertr.yaml
|
# 1. Configure sites in insertr.yaml
|
||||||
# 2. Start the server
|
# 2. Start development server (no file enhancement)
|
||||||
./insertr serve --dev-mode
|
./insertr serve --dev-mode
|
||||||
|
|
||||||
# 3. Your sites are automatically registered and enhanced
|
# 3. Editor loads content from database dynamically
|
||||||
# 4. Content changes via editor immediately update static files
|
# 4. No unwanted file modifications or page reloads during development
|
||||||
|
|
||||||
|
# 5. For production deployment:
|
||||||
|
./insertr serve # Enables automatic file enhancement
|
||||||
```
|
```
|
||||||
|
|
||||||
## ⚙️ Configuration
|
## ⚙️ Configuration
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func runServe(cmd *cobra.Command, args []string) {
|
|||||||
contentClient := content.NewDatabaseClient(database)
|
contentClient := content.NewDatabaseClient(database)
|
||||||
|
|
||||||
// Initialize site manager
|
// Initialize site manager
|
||||||
siteManager := content.NewSiteManager(contentClient, "./insertr-backups")
|
siteManager := content.NewSiteManager(contentClient, "./insertr-backups", devMode)
|
||||||
|
|
||||||
// Load sites from configuration
|
// Load sites from configuration
|
||||||
if siteConfigs := viper.Get("server.sites"); siteConfigs != nil {
|
if siteConfigs := viper.Get("server.sites"); siteConfigs != nil {
|
||||||
|
|||||||
@@ -24,10 +24,11 @@ type SiteManager struct {
|
|||||||
enhancer *Enhancer
|
enhancer *Enhancer
|
||||||
mutex sync.RWMutex
|
mutex sync.RWMutex
|
||||||
backupDir string
|
backupDir string
|
||||||
|
devMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSiteManager creates a new site manager
|
// NewSiteManager creates a new site manager
|
||||||
func NewSiteManager(contentClient ContentClient, backupDir string) *SiteManager {
|
func NewSiteManager(contentClient ContentClient, backupDir string, devMode bool) *SiteManager {
|
||||||
if backupDir == "" {
|
if backupDir == "" {
|
||||||
backupDir = "./insertr-backups"
|
backupDir = "./insertr-backups"
|
||||||
}
|
}
|
||||||
@@ -36,6 +37,7 @@ func NewSiteManager(contentClient ContentClient, backupDir string) *SiteManager
|
|||||||
sites: make(map[string]*SiteConfig),
|
sites: make(map[string]*SiteConfig),
|
||||||
enhancer: NewEnhancer(contentClient, ""), // siteID will be set per operation
|
enhancer: NewEnhancer(contentClient, ""), // siteID will be set per operation
|
||||||
backupDir: backupDir,
|
backupDir: backupDir,
|
||||||
|
devMode: devMode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,10 +105,26 @@ func (sm *SiteManager) GetAllSites() map[string]*SiteConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsAutoEnhanceEnabled checks if a site has auto-enhancement enabled
|
// IsAutoEnhanceEnabled checks if a site has auto-enhancement enabled
|
||||||
|
// Returns false in development mode to prevent unwanted file modifications and live-reload loops
|
||||||
func (sm *SiteManager) IsAutoEnhanceEnabled(siteID string) bool {
|
func (sm *SiteManager) IsAutoEnhanceEnabled(siteID string) bool {
|
||||||
sm.mutex.RLock()
|
sm.mutex.RLock()
|
||||||
defer sm.mutex.RUnlock()
|
defer sm.mutex.RUnlock()
|
||||||
|
|
||||||
|
// Disable auto-enhancement in development mode to prevent file modification conflicts with live-reload
|
||||||
|
if sm.devMode {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
site, exists := sm.sites[siteID]
|
||||||
|
return exists && site.AutoEnhance
|
||||||
|
}
|
||||||
|
|
||||||
|
// ForceEnhanceEnabled allows testing production behavior in development mode
|
||||||
|
// This method bypasses the dev_mode check for testing purposes
|
||||||
|
func (sm *SiteManager) ForceEnhanceEnabled(siteID string) bool {
|
||||||
|
sm.mutex.RLock()
|
||||||
|
defer sm.mutex.RUnlock()
|
||||||
|
|
||||||
site, exists := sm.sites[siteID]
|
site, exists := sm.sites[siteID]
|
||||||
return exists && site.AutoEnhance
|
return exists && site.AutoEnhance
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user