From 715df08cbe70c8e201e148635d5f83a228350d58 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 28 Sep 2019 08:42:58 -0500 Subject: [PATCH] Migrate API to .NET Core 3.0 (#31) Migrate API to .NET Core 3.0 (fixes #30) --- src/MyPrayerJournal.Api/Handlers.fs | 14 ++++++++++++++ src/MyPrayerJournal.Api/MyPrayerJournal.Api.fsproj | 6 +++--- src/MyPrayerJournal.Api/Program.fs | 5 +++-- src/app/package.json | 4 ++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/MyPrayerJournal.Api/Handlers.fs b/src/MyPrayerJournal.Api/Handlers.fs index b07c59f..b3a625f 100644 --- a/src/MyPrayerJournal.Api/Handlers.fs +++ b/src/MyPrayerJournal.Api/Handlers.fs @@ -85,6 +85,15 @@ module private Helpers = /// Flip JSON result so we can pipe into it let asJson<'T> next ctx (o : 'T) = json o next ctx + + /// Work-around to let the Json.NET serializer synchronously deserialize from the request stream + // TODO: Remove this once there is an async serializer + let allowSyncIO : HttpHandler = + fun next ctx -> + match ctx.Features.Get() with + | null -> () + | f -> f.AllowSynchronousIO <- true + next ctx /// Strongly-typed models for post requests @@ -156,6 +165,7 @@ module Request = /// POST /api/request let add : HttpHandler = authorize + >=> allowSyncIO >=> fun next ctx -> task { let! r = ctx.BindJsonAsync () @@ -187,6 +197,7 @@ module Request = /// POST /api/request/[req-id]/history let addHistory requestId : HttpHandler = authorize + >=> allowSyncIO >=> fun next ctx -> task { use sess = session ctx @@ -218,6 +229,7 @@ module Request = /// POST /api/request/[req-id]/note let addNote requestId : HttpHandler = authorize + >=> allowSyncIO >=> fun next ctx -> task { use sess = session ctx @@ -297,6 +309,7 @@ module Request = /// PATCH /api/request/[req-id]/snooze let snooze requestId : HttpHandler = authorize + >=> allowSyncIO >=> fun next ctx -> task { use sess = session ctx @@ -314,6 +327,7 @@ module Request = /// PATCH /api/request/[req-id]/recurrence let updateRecurrence requestId : HttpHandler = authorize + >=> allowSyncIO >=> fun next ctx -> task { use sess = session ctx diff --git a/src/MyPrayerJournal.Api/MyPrayerJournal.Api.fsproj b/src/MyPrayerJournal.Api/MyPrayerJournal.Api.fsproj index a74dfd3..40bf8f3 100644 --- a/src/MyPrayerJournal.Api/MyPrayerJournal.Api.fsproj +++ b/src/MyPrayerJournal.Api/MyPrayerJournal.Api.fsproj @@ -1,8 +1,8 @@  - netcoreapp2.2 - 2.0.1.0 + netcoreapp3.0 + 2.1.0.0 @@ -16,7 +16,7 @@ - + diff --git a/src/MyPrayerJournal.Api/Program.fs b/src/MyPrayerJournal.Api/Program.fs index 563fbb7..9a40810 100644 --- a/src/MyPrayerJournal.Api/Program.fs +++ b/src/MyPrayerJournal.Api/Program.fs @@ -90,11 +90,12 @@ module Configure = bldr.ConfigureServices svcs open Microsoft.Extensions.Logging + open Microsoft.Extensions.Hosting /// Configure logging let logging (bldr : IWebHostBuilder) = let logz (log : ILoggingBuilder) = - let env = log.Services.BuildServiceProvider().GetService () + let env = log.Services.BuildServiceProvider().GetService () match env.IsDevelopment () with | true -> log | false -> log.AddFilter(fun l -> l > LogLevel.Information) @@ -109,7 +110,7 @@ module Configure = let appConfig = Action ( fun (app : IApplicationBuilder) -> - let env = app.ApplicationServices.GetService () + let env = app.ApplicationServices.GetService () match env.IsDevelopment () with | true -> app.UseDeveloperExceptionPage () | false -> app.UseGiraffeErrorHandler Handlers.Error.error diff --git a/src/app/package.json b/src/app/package.json index 2f1451d..b2eb6f4 100644 --- a/src/app/package.json +++ b/src/app/package.json @@ -1,6 +1,6 @@ { "name": "my-prayer-journal", - "version": "2.0.1", + "version": "2.1.0", "description": "myPrayerJournal - Front End", "author": "Daniel J. Summers ", "private": true, @@ -10,7 +10,7 @@ "lint": "vue-cli-service lint", "apistart": "cd ../MyPrayerJournal.Api && dotnet run", "vue": "vue-cli-service build --modern && cd ../MyPrayerJournal.Api && dotnet run", - "publish": "vue-cli-service build --modern && cd ../MyPrayerJournal.Api && dotnet publish -c Release" + "publish": "vue-cli-service build --modern && cd ../MyPrayerJournal.Api && dotnet publish -c Release -r linux-x64 --self-contained false" }, "dependencies": { "auth0-js": "^9.7.3",