Skip to content

Commit

Permalink
Merge pull request #47 from fsbolero/minimal-api
Browse files Browse the repository at this point in the history
Use Minimal API on the server side
  • Loading branch information
Tarmil authored Dec 17, 2023
2 parents 1cefe73 + 1810181 commit 41fb14d
Showing 1 changed file with 37 additions and 48 deletions.
85 changes: 37 additions & 48 deletions content/application/src/Bolero.Template.1.Server/Startup.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Bolero.Template._1.Server
module Bolero.Template._1.Server.Program

open Microsoft.AspNetCore
open Microsoft.AspNetCore.Authentication.Cookies
Expand All @@ -14,73 +14,62 @@ open Bolero.Template._1
open Bolero.Templating.Server
//#endif

type Startup() =
[<EntryPoint>]
let main args =
let builder = WebApplication.CreateBuilder(args)

// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
member this.ConfigureServices(services: IServiceCollection) =
//#if (hostpage == "razor")
services.AddMvc().AddRazorRuntimeCompilation() |> ignore
builder.Services.AddMvc().AddRazorRuntimeCompilation() |> ignore
//#else
services.AddMvc() |> ignore
builder.Services.AddMvc() |> ignore
//#endif
services.AddServerSideBlazor() |> ignore
services
builder.Services.AddServerSideBlazor() |> ignore
//#if (!minimal)
.AddAuthorization()
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie()
.Services
.AddBoleroRemoting<BookService>()
builder.Services.AddAuthorization()
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie()
|> ignore
builder.Services.AddBoleroRemoting<BookService>() |> ignore
//#endif
//#if (hostpage != "html")
.AddBoleroHost()
builder.Services.AddBoleroHost() |> ignore
//#endif
//#if (hotreload_actual)
#if DEBUG
.AddHotReload(templateDir = __SOURCE_DIRECTORY__ + "/../Bolero.Template.1.Client")
builder.Services.AddHotReload(templateDir = __SOURCE_DIRECTORY__ + "/../Bolero.Template.1.Client") |> ignore
#endif
//#endif
|> ignore

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
member this.Configure(app: IApplicationBuilder, env: IWebHostEnvironment) =
if env.IsDevelopment() then
app.UseWebAssemblyDebugging()
let app = builder.Build()

if app.Environment.IsDevelopment() then
app.UseWebAssemblyDebugging()

app
.UseAuthentication()
.UseStaticFiles()
.UseRouting()
.UseAuthorization()
.UseBlazorFrameworkFiles()
|> ignore

app
.UseAuthentication()
.UseStaticFiles()
.UseRouting()
.UseAuthorization()
.UseBlazorFrameworkFiles()
.UseEndpoints(fun endpoints ->
//#if (hotreload_actual)
#if DEBUG
endpoints.UseHotReload()
app.UseHotReload()
#endif
//#endif
endpoints.MapBoleroRemoting() |> ignore
app.MapBoleroRemoting() |> ignore
//#if (hostpage == "razor")
endpoints.MapBlazorHub() |> ignore
endpoints.MapFallbackToPage("/_Host") |> ignore)
app.MapBlazorHub() |> ignore
app.MapFallbackToPage("/_Host") |> ignore
//#elseif (hostpage == "bolero")
endpoints.MapBlazorHub() |> ignore
endpoints.MapFallbackToBolero(Index.page) |> ignore)
app.MapBlazorHub() |> ignore
app.MapFallbackToBolero(Index.page) |> ignore
//#elseif (hostpage == "html")
endpoints.MapControllers() |> ignore
endpoints.MapFallbackToFile("index.html") |> ignore)
app.MapControllers() |> ignore
app.MapFallbackToFile("index.html") |> ignore
//#endif
|> ignore

module Program =
|> ignore

[<EntryPoint>]
let main args =
WebHost
.CreateDefaultBuilder(args)
.UseStaticWebAssets()
.UseStartup<Startup>()
.Build()
.Run()
0
app.Run()
0

0 comments on commit 41fb14d

Please sign in to comment.