From 49d9030f5030d7edbef374ea5edea842832f0afc Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Fri, 17 Sep 2021 20:13:32 -0400 Subject: [PATCH] Convert routes to endpoints (#31) --- src/PrayerTracker/App.fs | 17 +++++++++-------- src/PrayerTracker/PrayerTracker.fsproj | 1 - 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/PrayerTracker/App.fs b/src/PrayerTracker/App.fs index 0d1d00d..5ed4074 100644 --- a/src/PrayerTracker/App.fs +++ b/src/PrayerTracker/App.fs @@ -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(SystemClock.Instance) |> ignore let config = svc.BuildServiceProvider().GetRequiredService() @@ -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 @@ -144,7 +143,8 @@ module Configure = // Temp redirect to new URLs 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>().Value) - .UseGiraffe(webApp) + .UseEndpoints (fun e -> e.MapGiraffeEndpoints routes) |> ignore Views.I18N.setUpFactories <| app.ApplicationServices.GetRequiredService () diff --git a/src/PrayerTracker/PrayerTracker.fsproj b/src/PrayerTracker/PrayerTracker.fsproj index 7eec552..21f3089 100644 --- a/src/PrayerTracker/PrayerTracker.fsproj +++ b/src/PrayerTracker/PrayerTracker.fsproj @@ -24,7 +24,6 @@ -