diff --git a/src/Bolero.Server/Extensions.fs b/src/Bolero.Server/Extensions.fs index dd5d7ed..3e575ff 100644 --- a/src/Bolero.Server/Extensions.fs +++ b/src/Bolero.Server/Extensions.fs @@ -88,7 +88,9 @@ type ServerComponentsExtensions = static member RenderBoleroScript(html: IHtmlHelper, config: IBoleroHostConfig) = html.Raw(BoleroHostConfig.Body(config)) - /// Configure the hosting of server-side and WebAssembly Bolero components. + /// + /// Configure the hosting of server-side and WebAssembly Bolero components using Bolero's legacy render mode handling. + /// /// If true, use server-side Bolero; if false, use WebAssembly. Default is false. /// If true, prerender the initial view in the served HTML. Default is true. /// @@ -111,9 +113,21 @@ type ServerComponentsExtensions = else this.AddSingleton( { new IBoleroHostConfig with + member _.IsInteractiveComponents = false member _.IsServer = server member _.IsPrerendered = prerendered }) + /// + /// Configure the hosting of Bolero components using interactive render modes. + /// + [] + static member AddBoleroComponents(this: IServiceCollection) = + this.AddSingleton( + { new IBoleroHostConfig with + member _.IsInteractiveComponents = true + member _.IsServer = false + member _.IsPrerendered = false }) + /// /// Adds a route endpoint that will match requests for non-file-names with the lowest possible priority. /// The request will be routed to a Bolero page. diff --git a/src/Bolero.Server/HostConfig.fs b/src/Bolero.Server/HostConfig.fs index eac4f48..018edf4 100644 --- a/src/Bolero.Server/HostConfig.fs +++ b/src/Bolero.Server/HostConfig.fs @@ -24,12 +24,24 @@ open Microsoft.AspNetCore.Http open Microsoft.Extensions.Hosting /// -/// The Bolero hosting configuration set by . +/// The Bolero hosting configuration set by +/// or . /// type IBoleroHostConfig = - /// If true, use server-side Bolero; if false, use WebAssembly. + /// + /// If true, use Bolero with interactive render modes, and bypass and . + /// If false, use Bolero's legacy render mode handling. + /// + abstract IsInteractiveComponents: bool + /// + /// If true, use server-side Bolero; if false, use WebAssembly. + /// Only applies if is false. + /// abstract IsServer: bool - /// If true, prerender the initial view in the served HTML. + /// + /// If true, prerender the initial view in the served HTML. + /// Only applies if is false. + /// abstract IsPrerendered: bool /// @@ -56,7 +68,11 @@ type BoleroHostConfig(baseConfig: IBoleroHostBaseConfig, env: IHostEnvironment, interface IBoleroHostConfig with member this.IsServer = this.IsServer member this.IsPrerendered = this.IsPrerendered + member this.IsInteractiveComponents = false static member internal Body(config: IBoleroHostConfig) = - let k = if config.IsServer then "server" else "webassembly" + let k = + if config.IsInteractiveComponents then "web" + elif config.IsServer then "server" + else "webassembly" $"""""" diff --git a/tests/Remoting.Client/Main.fs b/tests/Remoting.Client/Main.fs index feb56a2..3996752 100644 --- a/tests/Remoting.Client/Main.fs +++ b/tests/Remoting.Client/Main.fs @@ -21,6 +21,7 @@ module Bolero.Tests.Remoting.Client open System.Collections.Generic +open Microsoft.AspNetCore.Components open Microsoft.AspNetCore.Components.Authorization open Bolero open Bolero.Html @@ -220,6 +221,7 @@ let Display model dispatch = } } +[] type MyApp() = inherit ProgramComponent() diff --git a/tests/Remoting.Server/Startup.fs b/tests/Remoting.Server/Startup.fs index d08c211..e526392 100644 --- a/tests/Remoting.Server/Startup.fs +++ b/tests/Remoting.Server/Startup.fs @@ -38,18 +38,22 @@ module Page = open Bolero.Html open Bolero.Server.Html - let index = doctypeHtml { - head { - title { "Bolero (remoting)" } - meta { attr.charset "UTF-8" } - ``base`` { attr.href "/" } - } - body { - div { attr.id "main"; comp } - script { attr.src "_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js" } - boleroScript - } - } + type Page() = + inherit Bolero.Component() + + override _.Render() = + doctypeHtml { + head { + title { "Bolero (remoting)" } + meta { attr.charset "UTF-8" } + Bolero.Html.``base`` { attr.href "/" } + } + body { + div { attr.id "main"; comp } + script { attr.src "_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js" } + boleroScript + } + } type MyApiHandler(log: ILogger, ctx: IRemoteContext) = inherit RemoteHandler() @@ -91,14 +95,16 @@ type MyApiHandler(log: ILogger, ctx: IRemoteContext) = type Startup() = member this.ConfigureServices(services: IServiceCollection) = - services.AddMvc() |> ignore + services.AddRazorComponents() + .AddInteractiveServerComponents() + .AddInteractiveWebAssemblyComponents() + |> ignore services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie() |> ignore services .AddBoleroRemoting() - .AddBoleroHost() - .AddServerSideBlazor() + .AddBoleroComponents() |> ignore services.AddSwaggerForSystemTextJson(JsonFSharpOptions()) |> ignore services.AddEndpointsApiExplorer() |> ignore @@ -110,13 +116,16 @@ type Startup() = .UseSwaggerUI() .UseRouting() .UseAuthorization() - .UseBlazorFrameworkFiles() + .UseAntiforgery() .UseEndpoints(fun endpoints -> - endpoints.MapBlazorHub() |> ignore endpoints.MapBoleroRemoting() .WithOpenApi() |> ignore - endpoints.MapFallbackToBolero(Page.index) |> ignore) + endpoints.MapRazorComponents() + .AddInteractiveServerRenderMode() + .AddInteractiveWebAssemblyRenderMode() + .AddAdditionalAssemblies(typeof.Assembly) + |> ignore) |> ignore if env.IsDevelopment() then