Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Minimal API on the server side #47

Merged
merged 2 commits into from
Dec 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading