clavitor/design-system/server-temp.go

51 lines
1.2 KiB
Go

package main
import (
"context"
"log"
"net/http"
"time"
)
func main() {
fs := http.FileServer(http.Dir("."))
// Wrap to add no-cache headers
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
fs.ServeHTTP(w, r)
})
// Auto-shutdown after 60 minutes
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Minute)
defer cancel()
server := &http.Server{
Addr: "0.0.0.0:8888",
Handler: handler,
}
log.Println("Serving on http://192.168.1.16:8888")
log.Println("Auto-shutdown in 60 minutes")
// Run server in goroutine
go func() {
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatalf("Server error: %v", err)
}
}()
// Wait for shutdown signal
<-ctx.Done()
log.Println("Shutting down...")
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer shutdownCancel()
if err := server.Shutdown(shutdownCtx); err != nil {
log.Printf("Shutdown error: %v", err)
}
log.Println("Server stopped")
}