V2 #1
|
@ -26,16 +26,11 @@ open System.Collections.Concurrent
|
||||||
/// settings update page</remarks>
|
/// settings update page</remarks>
|
||||||
module WebLogCache =
|
module WebLogCache =
|
||||||
|
|
||||||
/// Create the full path of the request
|
|
||||||
let private fullPath (ctx : HttpContext) =
|
|
||||||
$"{ctx.Request.Scheme}://{ctx.Request.Host.Value}{ctx.Request.Path.Value}"
|
|
||||||
|
|
||||||
/// The cache of web log details
|
/// The cache of web log details
|
||||||
let mutable private _cache : WebLog list = []
|
let mutable private _cache : WebLog list = []
|
||||||
|
|
||||||
/// Try to get the web log for the current request (longest matching URL base wins)
|
/// Try to get the web log for the current request (longest matching URL base wins)
|
||||||
let tryGet ctx =
|
let tryGet (path : string) =
|
||||||
let path = fullPath ctx
|
|
||||||
_cache
|
_cache
|
||||||
|> List.filter (fun wl -> path.StartsWith wl.urlBase)
|
|> List.filter (fun wl -> path.StartsWith wl.urlBase)
|
||||||
|> List.sortByDescending (fun wl -> wl.urlBase.Length)
|
|> List.sortByDescending (fun wl -> wl.urlBase.Length)
|
||||||
|
|
|
@ -1,17 +1,26 @@
|
||||||
open Microsoft.AspNetCore.Http
|
open Microsoft.AspNetCore.Http
|
||||||
|
open Microsoft.Extensions.Logging
|
||||||
open MyWebLog
|
open MyWebLog
|
||||||
|
|
||||||
/// Middleware to derive the current web log
|
/// Middleware to derive the current web log
|
||||||
type WebLogMiddleware (next : RequestDelegate) =
|
type WebLogMiddleware (next : RequestDelegate, log : ILogger<WebLogMiddleware>) =
|
||||||
|
|
||||||
|
/// Is the debug level enabled on the logger?
|
||||||
|
let isDebug = log.IsEnabled LogLevel.Debug
|
||||||
|
|
||||||
member this.InvokeAsync (ctx : HttpContext) = task {
|
member this.InvokeAsync (ctx : HttpContext) = task {
|
||||||
match WebLogCache.tryGet ctx with
|
/// Create the full path of the request
|
||||||
|
let path = $"{ctx.Request.Scheme}://{ctx.Request.Host.Value}{ctx.Request.Path.Value}"
|
||||||
|
match WebLogCache.tryGet path with
|
||||||
| Some webLog ->
|
| Some webLog ->
|
||||||
|
if isDebug then log.LogDebug $"Resolved web log {WebLogId.toString webLog.id} for {path}"
|
||||||
ctx.Items["webLog"] <- webLog
|
ctx.Items["webLog"] <- webLog
|
||||||
if PageListCache.exists ctx then () else do! PageListCache.update ctx
|
if PageListCache.exists ctx then () else do! PageListCache.update ctx
|
||||||
if CategoryCache.exists ctx then () else do! CategoryCache.update ctx
|
if CategoryCache.exists ctx then () else do! CategoryCache.update ctx
|
||||||
return! next.Invoke ctx
|
return! next.Invoke ctx
|
||||||
| None -> ctx.Response.StatusCode <- 404
|
| None ->
|
||||||
|
if isDebug then log.LogDebug $"No resolved web log for {path}"
|
||||||
|
ctx.Response.StatusCode <- 404
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,7 +162,6 @@ open Microsoft.AspNetCore.Authentication.Cookies
|
||||||
open Microsoft.AspNetCore.Builder
|
open Microsoft.AspNetCore.Builder
|
||||||
open Microsoft.AspNetCore.HttpOverrides
|
open Microsoft.AspNetCore.HttpOverrides
|
||||||
open Microsoft.Extensions.Configuration
|
open Microsoft.Extensions.Configuration
|
||||||
open Microsoft.Extensions.Logging
|
|
||||||
open MyWebLog.ViewModels
|
open MyWebLog.ViewModels
|
||||||
open RethinkDB.DistributedCache
|
open RethinkDB.DistributedCache
|
||||||
open RethinkDb.Driver.FSharp
|
open RethinkDb.Driver.FSharp
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"hostname": "data02.bitbadger.solutions",
|
"hostname": "data02.bitbadger.solutions",
|
||||||
"database": "myWebLog_dev"
|
"database": "myWebLog_dev"
|
||||||
},
|
},
|
||||||
"Generator": "myWebLog 2.0-alpha10",
|
"Generator": "myWebLog 2.0-alpha11",
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"MyWebLog.Handlers": "Debug"
|
"MyWebLog.Handlers": "Debug"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user