Convert routes to endpoints (#31)

This commit is contained in:
Daniel J. Summers 2021-09-17 20:13:32 -04:00
parent 7a2f2bd92d
commit 49d9030f50
2 changed files with 9 additions and 9 deletions

View File

@ -9,7 +9,7 @@ module Configure =
open Cookies
open Giraffe
open Giraffe.TokenRouter
open Giraffe.EndpointRouting
open Microsoft.AspNetCore.Localization
open Microsoft.AspNetCore.Server.Kestrel.Core
open Microsoft.EntityFrameworkCore
@ -49,6 +49,7 @@ module Configure =
.AddDistributedMemoryCache()
.AddSession()
.AddAntiforgery()
.AddRouting()
.AddSingleton<IClock>(SystemClock.Instance)
|> ignore
let config = svc.BuildServiceProvider().GetRequiredService<IConfiguration>()
@ -60,11 +61,9 @@ module Configure =
|> ignore
/// Routes for PrayerTracker
let webApp =
router Handlers.CommonFunctions.fourOhFour [
// Traditional web app routes
subRoute"/web" [
GET [
let routes =
[ subRoute "/web" [
GET_HEAD [
subRoute "/church" [
route "es" Handlers.Church.maintain
routef "/%O/edit" Handlers.Church.edit
@ -145,6 +144,7 @@ module Configure =
route "/" (redirectTo false "/web/")
]
/// Giraffe error handler
let errorHandler (ex : exn) (logger : ILogger) =
logger.LogError(EventId(), ex, "An unhandled exception has occurred while executing the request.")
clearResponse >=> setStatusCode 500 >=> text ex.Message
@ -171,9 +171,10 @@ module Configure =
app.UseGiraffeErrorHandler errorHandler)
.UseStatusCodePagesWithReExecute("/error/{0}")
.UseStaticFiles()
.UseRouting()
.UseSession()
.UseRequestLocalization(app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>().Value)
.UseGiraffe(webApp)
.UseEndpoints (fun e -> e.MapGiraffeEndpoints routes)
|> ignore
Views.I18N.setUpFactories <| app.ApplicationServices.GetRequiredService<IStringLocalizerFactory> ()

View File

@ -24,7 +24,6 @@
<ItemGroup>
<PackageReference Include="Giraffe" Version="5.0.0" />
<PackageReference Include="Giraffe.TokenRouter" Version="1.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.10" />
</ItemGroup>