Update SDK; htmx serving now works (#59)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
@@ -7,7 +7,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings*.json" CopyToOutputDirectory="Always" />
|
||||
<Compile Include="Caches.fs" />
|
||||
<Compile Include="ViewContext.fs" />
|
||||
<Compile Include="Template.fs" />
|
||||
|
||||
+42
-40
@@ -1,7 +1,4 @@
|
||||
open Microsoft.AspNetCore.Hosting
|
||||
open Microsoft.AspNetCore.Http
|
||||
open Microsoft.Data.Sqlite
|
||||
open Microsoft.Extensions.Configuration
|
||||
open Microsoft.AspNetCore.Http
|
||||
open Microsoft.Extensions.Logging
|
||||
open MyWebLog
|
||||
|
||||
@@ -30,6 +27,7 @@ type WebLogMiddleware(next: RequestDelegate, log: ILogger<WebLogMiddleware>) =
|
||||
}
|
||||
|
||||
|
||||
open System
|
||||
open Giraffe.Htmx
|
||||
|
||||
/// Middleware to check redirects for the current web log
|
||||
@@ -37,7 +35,7 @@ type RedirectRuleMiddleware(next: RequestDelegate, _log: ILogger<RedirectRuleMid
|
||||
|
||||
/// Shorthand for case-insensitive string equality
|
||||
let ciEquals str1 str2 =
|
||||
System.String.Equals(str1, str2, System.StringComparison.InvariantCultureIgnoreCase)
|
||||
String.Equals(str1, str2, StringComparison.InvariantCultureIgnoreCase)
|
||||
|
||||
member _.InvokeAsync(ctx: HttpContext) = task {
|
||||
let path = ctx.Request.Path.Value.ToLower()
|
||||
@@ -57,9 +55,9 @@ type RedirectRuleMiddleware(next: RequestDelegate, _log: ILogger<RedirectRuleMid
|
||||
}
|
||||
|
||||
|
||||
open System
|
||||
open System.IO
|
||||
open BitBadger.Documents
|
||||
open Microsoft.Extensions.Configuration
|
||||
open Microsoft.Extensions.DependencyInjection
|
||||
open MyWebLog.Data
|
||||
open Newtonsoft.Json
|
||||
@@ -137,8 +135,10 @@ open Giraffe
|
||||
open Giraffe.EndpointRouting
|
||||
open Microsoft.AspNetCore.Authentication.Cookies
|
||||
open Microsoft.AspNetCore.Builder
|
||||
open Microsoft.AspNetCore.HttpOverrides
|
||||
open Microsoft.Extensions.Caching.Distributed
|
||||
open Microsoft.AspNetCore.HttpOverrides
|
||||
open Microsoft.AspNetCore.Hosting
|
||||
open Microsoft.Data.Sqlite
|
||||
open NeoSmart.Caching.Sqlite
|
||||
open RethinkDB.DistributedCache
|
||||
|
||||
@@ -150,19 +150,20 @@ let main args =
|
||||
ContentRootPath = Directory.GetCurrentDirectory(),
|
||||
WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot"),
|
||||
Args = args))
|
||||
let _ = builder.Services.Configure<ForwardedHeadersOptions>(
|
||||
let _ = builder.WebHost.UseStaticWebAssets()
|
||||
builder.Services
|
||||
.Configure<ForwardedHeadersOptions>(
|
||||
fun (opts: ForwardedHeadersOptions) ->
|
||||
opts.ForwardedHeaders <- ForwardedHeaders.XForwardedFor ||| ForwardedHeaders.XForwardedProto)
|
||||
let _ =
|
||||
builder.Services
|
||||
.AddLogging()
|
||||
.AddAuthorization()
|
||||
.AddAntiforgery()
|
||||
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
|
||||
.AddCookie(fun opts ->
|
||||
opts.ExpireTimeSpan <- TimeSpan.FromMinutes 60.
|
||||
opts.SlidingExpiration <- true
|
||||
opts.AccessDeniedPath <- "/forbidden")
|
||||
let _ = builder.Services.AddLogging()
|
||||
let _ = builder.Services.AddAuthorization()
|
||||
let _ = builder.Services.AddAntiforgery()
|
||||
|> ignore
|
||||
|
||||
let sp = builder.Services.BuildServiceProvider()
|
||||
let data = DataImplementation.get sp
|
||||
@@ -178,37 +179,37 @@ let main args =
|
||||
match data with
|
||||
| :? RethinkDbData as rethink ->
|
||||
// A RethinkDB connection is designed to work as a singleton
|
||||
let _ = builder.Services.AddSingleton<IData> data
|
||||
let _ =
|
||||
builder.Services.AddDistributedRethinkDBCache(fun opts ->
|
||||
builder.Services
|
||||
.AddSingleton<IData>(data)
|
||||
.AddDistributedRethinkDBCache(fun opts ->
|
||||
opts.TableName <- "Session"
|
||||
opts.Connection <- rethink.Conn)
|
||||
()
|
||||
|> ignore
|
||||
| :? SQLiteData ->
|
||||
// ADO.NET connections are designed to work as per-request instantiation
|
||||
// ADO.NET connections are designed to work as per-request instantiation; use SQLite for caching as well
|
||||
let cfg = sp.GetRequiredService<IConfiguration>()
|
||||
let _ = builder.Services.AddScoped<SqliteConnection>(fun sp -> Sqlite.Configuration.dbConn ())
|
||||
let _ = builder.Services.AddScoped<IData, SQLiteData>()
|
||||
// Use SQLite for caching as well
|
||||
let cachePath = defaultArg (Option.ofObj (cfg.GetConnectionString "SQLiteCachePath")) "./data/session.db"
|
||||
let _ = builder.Services.AddSqliteCache(fun o -> o.CachePath <- cachePath)
|
||||
()
|
||||
builder.Services
|
||||
.AddScoped<SqliteConnection>(fun sp -> Sqlite.Configuration.dbConn ())
|
||||
.AddScoped<IData, SQLiteData>()
|
||||
.AddSqliteCache(fun o -> o.CachePath <- cachePath)
|
||||
|> ignore
|
||||
| :? PostgresData as postgres ->
|
||||
// ADO.NET Data Sources are designed to work as singletons
|
||||
let _ = builder.Services.AddSingleton<NpgsqlDataSource>(Postgres.Configuration.dataSource ())
|
||||
let _ = builder.Services.AddSingleton<IData> postgres
|
||||
let _ =
|
||||
builder.Services.AddSingleton<IDistributedCache>(fun _ ->
|
||||
Postgres.DistributedCache() :> IDistributedCache)
|
||||
()
|
||||
builder.Services
|
||||
.AddSingleton<NpgsqlDataSource>(Postgres.Configuration.dataSource ())
|
||||
.AddSingleton<IData>(postgres)
|
||||
.AddSingleton<IDistributedCache>(fun _ -> Postgres.DistributedCache() :> IDistributedCache)
|
||||
|> ignore
|
||||
| _ -> ()
|
||||
|
||||
let _ = builder.Services.AddSession(fun opts ->
|
||||
builder.Services
|
||||
.AddSession(fun opts ->
|
||||
opts.IdleTimeout <- TimeSpan.FromMinutes 60.
|
||||
opts.Cookie.HttpOnly <- true
|
||||
opts.Cookie.IsEssential <- true)
|
||||
let _ = builder.Services.AddGiraffe()
|
||||
let _ = builder.WebHost.UseStaticWebAssets()
|
||||
.AddGiraffe()
|
||||
|> ignore
|
||||
|
||||
// Set up DotLiquid
|
||||
DotLiquidBespoke.register ()
|
||||
@@ -243,14 +244,15 @@ let main args =
|
||||
|> isNotNull
|
||||
|> function true -> app.UseCanonicalDomains() |> ignore | false -> ()
|
||||
|
||||
let _ = app.UseCookiePolicy(CookiePolicyOptions(MinimumSameSitePolicy = SameSiteMode.Strict))
|
||||
let _ = app.UseMiddleware<WebLogMiddleware>()
|
||||
let _ = app.UseMiddleware<RedirectRuleMiddleware>()
|
||||
let _ = app.UseAuthentication()
|
||||
let _ = app.UseRouting()
|
||||
let _ = app.UseSession()
|
||||
let _ = app.UseGiraffe Handlers.Routes.endpoints
|
||||
let _ = app.UseStaticFiles()
|
||||
app .UseCookiePolicy(CookiePolicyOptions(MinimumSameSitePolicy = SameSiteMode.Strict))
|
||||
.UseMiddleware<WebLogMiddleware>()
|
||||
.UseMiddleware<RedirectRuleMiddleware>()
|
||||
.UseAuthentication()
|
||||
.UseStaticFiles()
|
||||
.UseRouting()
|
||||
.UseSession()
|
||||
.UseGiraffe Handlers.Routes.endpoints
|
||||
|> ignore
|
||||
|
||||
do! app.RunAsync()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user