Return client refresh from redir rule if htmx (#54)
This commit is contained in:
parent
1f7d415868
commit
c19f92889e
@ -26,6 +26,8 @@ type WebLogMiddleware(next: RequestDelegate, log: ILogger<WebLogMiddleware>) =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
open Giraffe.Htmx
|
||||||
|
|
||||||
/// Middleware to check redirects for the current web log
|
/// Middleware to check redirects for the current web log
|
||||||
type RedirectRuleMiddleware(next: RequestDelegate, _log: ILogger<RedirectRuleMiddleware>) =
|
type RedirectRuleMiddleware(next: RequestDelegate, _log: ILogger<RedirectRuleMiddleware>) =
|
||||||
|
|
||||||
@ -44,6 +46,8 @@ type RedirectRuleMiddleware(next: RequestDelegate, _log: ILogger<RedirectRuleMid
|
|||||||
| WebLogCache.CachedRedirectRule.RegEx (regExFrom, patternTo) ->
|
| WebLogCache.CachedRedirectRule.RegEx (regExFrom, patternTo) ->
|
||||||
if regExFrom.IsMatch path then Some (regExFrom.Replace(path, patternTo)) else None)
|
if regExFrom.IsMatch path then Some (regExFrom.Replace(path, patternTo)) else None)
|
||||||
match matched with
|
match matched with
|
||||||
|
| Some url when url.StartsWith "http" && ctx.Request.IsHtmx ->
|
||||||
|
do! ctx.Response.WriteAsync $"""<script>window.location.href = "{url}"</script>"""
|
||||||
| Some url -> ctx.Response.Redirect(url, permanent = true)
|
| Some url -> ctx.Response.Redirect(url, permanent = true)
|
||||||
| None -> return! next.Invoke ctx
|
| None -> return! next.Invoke ctx
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user