|
@@ -1,43 +1,47 @@
|
|
|
module App.Server
|
|
|
|
|
|
-open System.Threading.Tasks
|
|
|
+open System.Data
|
|
|
open Donald
|
|
|
open Falco
|
|
|
+open Falco.Host
|
|
|
open Microsoft.AspNetCore.Builder
|
|
|
open Microsoft.AspNetCore.Hosting
|
|
|
open Microsoft.Extensions.DependencyInjection
|
|
|
open Microsoft.Extensions.Logging
|
|
|
+open Npgsql
|
|
|
|
|
|
-let buildServer (connectionFactory : DbConnectionFactory) : Host.ConfigureWebHost =
|
|
|
- let configureLogging (log : ILoggingBuilder) =
|
|
|
- log.ClearProviders()
|
|
|
- |> ignore
|
|
|
+type ConnectionString = string
|
|
|
+type ConfigureLogging = ILoggingBuilder -> unit
|
|
|
+type ConfigureServices = DbConnectionFactory -> IServiceCollection -> unit
|
|
|
+type ConfigureApp = HttpEndpoint list -> IApplicationBuilder -> unit
|
|
|
+type ConfigureServer = ConnectionString -> ConfigureWebHost
|
|
|
|
|
|
- let configureServices
|
|
|
- (connectionFactory : DbConnectionFactory)
|
|
|
- (services : IServiceCollection) =
|
|
|
- services.AddRouting()
|
|
|
+let configure : ConfigureServer =
|
|
|
+ let configureLogging : ConfigureLogging =
|
|
|
+ fun log ->
|
|
|
+ log.ClearProviders()
|
|
|
+ |> ignore
|
|
|
+
|
|
|
+ let configureServices : ConfigureServices =
|
|
|
+ fun connectionFactory services ->
|
|
|
+ services
|
|
|
+ .AddRouting()
|
|
|
.AddSingleton<DbConnectionFactory>(connectionFactory)
|
|
|
- |> ignore
|
|
|
+ |> ignore
|
|
|
|
|
|
- let configure
|
|
|
- (routes : HttpEndpoint list)
|
|
|
- (app : IApplicationBuilder) =
|
|
|
- let handleNotFound : HttpHandler =
|
|
|
- fun ctx ->
|
|
|
- Response.withStatusCode 404 ctx |> ignore
|
|
|
- Task.CompletedTask
|
|
|
-
|
|
|
- app.UseRouting()
|
|
|
- .UseHttpEndPoints(routes)
|
|
|
- .UseNotFoundHandler(handleNotFound)
|
|
|
- |> ignore
|
|
|
+ let configure : ConfigureApp =
|
|
|
+ fun endpoints app ->
|
|
|
+ app.UseRouting()
|
|
|
+ .UseHttpEndPoints(endpoints)
|
|
|
+ |> ignore
|
|
|
|
|
|
- fun (routes : HttpEndpoint list)
|
|
|
- (webHost : IWebHostBuilder) ->
|
|
|
+ fun connectionString endpoints webHost ->
|
|
|
+ let connectionFactory =
|
|
|
+ fun () -> new NpgsqlConnection(connectionString) :> IDbConnection
|
|
|
+
|
|
|
webHost
|
|
|
.UseKestrel()
|
|
|
.ConfigureLogging(configureLogging)
|
|
|
.ConfigureServices(configureServices connectionFactory)
|
|
|
- .Configure(configure routes)
|
|
|
- |> ignore
|
|
|
+ .Configure(configure endpoints)
|
|
|
+ |> ignore
|