diff --git a/src/Bolero.Server/Extensions.fs b/src/Bolero.Server/Extensions.fs index dd5d7ed..153381a 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 _.IsInteractiveRender = 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 _.IsInteractiveRender = 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..069d01c 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 IsInteractiveRender: 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.IsInteractiveRender = false static member internal Body(config: IBoleroHostConfig) = - let k = if config.IsServer then "server" else "webassembly" + let k = + if config.IsInteractiveRender 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..5250de2 100644 --- a/tests/Remoting.Server/Startup.fs +++ b/tests/Remoting.Server/Startup.fs @@ -51,6 +51,10 @@ module Page = } } + type Page() = + inherit Bolero.Component() + override _.Render() = index + 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