mirror of
https://github.com/axzilla/templui.git
synced 2025-02-23 18:04:07 +00:00
18 lines
417 B
Go
18 lines
417 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/axzilla/templui/internal/config"
|
|
)
|
|
|
|
func WithPreviewCheck(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
isPreview := strings.HasPrefix(r.Host, "preview.")
|
|
ctx := context.WithValue(r.Context(), config.PreviewContextKey, isPreview)
|
|
next.ServeHTTP(w, r.WithContext(ctx))
|
|
})
|
|
}
|