diff --git a/Dockerfile b/Dockerfile index ca0cd02..38a3a44 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,12 @@ # Elsa Custom Server — Docker image # Multi-stage build so the final image only carries the ASP.NET runtime. -FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build WORKDIR /source # Restore first for better layer caching. COPY src/Elsa.CustomServer/Elsa.CustomServer.csproj src/Elsa.CustomServer/ +COPY src/Elsa.Studio.Wasm/Elsa.Studio.Wasm.csproj src/Elsa.Studio.Wasm/ RUN dotnet restore src/Elsa.CustomServer/Elsa.CustomServer.csproj # Then copy the rest and publish. @@ -13,7 +14,7 @@ COPY src/ src/ RUN dotnet publish src/Elsa.CustomServer/Elsa.CustomServer.csproj \ -c Release -o /app/publish --no-restore /p:UseAppHost=false -FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime WORKDIR /app COPY --from=build /app/publish ./ diff --git a/src/Elsa.CustomServer/Elsa.CustomServer.csproj b/src/Elsa.CustomServer/Elsa.CustomServer.csproj index 94b1947..38e3b37 100644 --- a/src/Elsa.CustomServer/Elsa.CustomServer.csproj +++ b/src/Elsa.CustomServer/Elsa.CustomServer.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable Elsa.CustomServer @@ -9,17 +9,23 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/src/Elsa.CustomServer/Pages/_Host.cshtml b/src/Elsa.CustomServer/Pages/_Host.cshtml new file mode 100644 index 0000000..e0f9c9c --- /dev/null +++ b/src/Elsa.CustomServer/Pages/_Host.cshtml @@ -0,0 +1,59 @@ +@page "/" +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@inject IConfiguration Configuration +@{ + // The Studio talks to the API on the same origin. HTTP__BASEURL sets the public URL; + // Hosting:ApiPrefix defaults to /elsa/api which is where AddWorkflowsApi mounts. + var baseUrl = Configuration["Hosting:BaseUrl"] ?? Configuration["Http:BaseUrl"] ?? ""; + var apiPrefix = (Configuration["Hosting:ApiPrefix"] ?? "elsa/api").TrimStart('/'); + var apiUrl = string.IsNullOrEmpty(baseUrl) + ? "/" + apiPrefix + : baseUrl.TrimEnd('/') + "/" + apiPrefix; +} + + + + + + + Elsa Studio + + + + + + + + + + + + + + + + + +
+
+
Loading...
+
+
+ +
+ An unhandled error has occurred. + Reload + 🗙 +
+ + + + + + + + + + diff --git a/src/Elsa.CustomServer/Program.cs b/src/Elsa.CustomServer/Program.cs index 05d4b9c..eb7040d 100644 --- a/src/Elsa.CustomServer/Program.cs +++ b/src/Elsa.CustomServer/Program.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.HttpOverrides; var builder = WebApplication.CreateBuilder(args); +builder.WebHost.UseStaticWebAssets(); var configuration = builder.Configuration; var identitySection = configuration.GetSection("Identity"); var identityTokenSection = identitySection.GetSection("Tokens"); @@ -34,7 +35,7 @@ builder.Services.AddElsa(elsa => .UseLiquid(liquid => liquid.FluidOptions = options => options.Encoder = HtmlEncoder.Default); }); -// Studio (whichever host) is on a different origin, so allow it in. +// Same-origin Studio, but keep CORS permissive to allow API access from other tools. builder.Services.AddCors(cors => cors.AddDefaultPolicy(p => p .AllowAnyHeader() .AllowAnyMethod() @@ -42,6 +43,7 @@ builder.Services.AddCors(cors => cors.AddDefaultPolicy(p => p .WithExposedHeaders("x-elsa-workflow-instance-id"))); builder.Services.AddHealthChecks(); +builder.Services.AddRazorPages(); // Traefik terminates TLS in front of us; without this, self-generated URLs come out as http:// builder.Services.Configure(o => @@ -54,14 +56,16 @@ builder.Services.Configure(o => var app = builder.Build(); app.UseForwardedHeaders(); -app.UseCors(); +app.UseBlazorFrameworkFiles(); +app.UseStaticFiles(); app.UseRouting(); +app.UseCors(); app.UseAuthentication(); app.UseAuthorization(); app.UseWorkflowsApi(); app.UseWorkflows(); app.UseJsonSerializationErrorHandler(); app.MapHealthChecks("/health"); -app.MapGet("/", () => Results.Ok(new { name = "Elsa Custom Server", status = "ok" })); +app.MapFallbackToPage("/_Host"); app.Run(); diff --git a/src/Elsa.Studio.Wasm/Elsa.Studio.Wasm.csproj b/src/Elsa.Studio.Wasm/Elsa.Studio.Wasm.csproj new file mode 100644 index 0000000..57e6109 --- /dev/null +++ b/src/Elsa.Studio.Wasm/Elsa.Studio.Wasm.csproj @@ -0,0 +1,24 @@ + + + + net9.0 + enable + enable + Elsa.Studio.Wasm + Elsa.Studio.Wasm + + + + + + + + + + + + + + + + diff --git a/src/Elsa.Studio.Wasm/MainLayout.razor b/src/Elsa.Studio.Wasm/MainLayout.razor new file mode 100644 index 0000000..724fc91 --- /dev/null +++ b/src/Elsa.Studio.Wasm/MainLayout.razor @@ -0,0 +1,5 @@ +@inherits LayoutComponentBase + +
+ @Body +
diff --git a/src/Elsa.Studio.Wasm/Program.cs b/src/Elsa.Studio.Wasm/Program.cs new file mode 100644 index 0000000..4d66a1f --- /dev/null +++ b/src/Elsa.Studio.Wasm/Program.cs @@ -0,0 +1,51 @@ +using System.Text.Json; +using Elsa.Studio.Contracts; +using Elsa.Studio.Core.BlazorWasm.Extensions; +using Elsa.Studio.Dashboard.Extensions; +using Elsa.Studio.Extensions; +using Elsa.Studio.Authentication.ElsaIdentity.BlazorWasm.Extensions; +using Elsa.Studio.Login.BlazorWasm.Extensions; +using Elsa.Studio.Login.HttpMessageHandlers; +using Elsa.Studio.Models; +using Elsa.Studio.Options; +using Elsa.Studio.Shell; +using Elsa.Studio.Shell.Extensions; +using Elsa.Studio.Workflows.Designer.Extensions; +using Elsa.Studio.Workflows.Extensions; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; +using Microsoft.Extensions.Options; +using Microsoft.JSInterop; + +var builder = WebAssemblyHostBuilder.CreateDefault(args); + +builder.RootComponents.Add("#app"); +builder.RootComponents.Add("head::after"); +builder.RootComponents.RegisterCustomElsaStudioElements(); + +var backendApiConfig = new BackendApiConfig +{ + ConfigureBackendOptions = options => builder.Configuration.GetSection("Backend").Bind(options), + ConfigureHttpClientBuilder = options => options.AuthenticationHandler = typeof(AuthenticatingApiHttpMessageHandler) +}; + +builder.Services.AddCore(); +builder.Services.AddShell(); +builder.Services.AddRemoteBackend(backendApiConfig); +builder.Services.AddLoginModule(); +builder.Services.AddElsaIdentity(); +builder.Services.AddDashboardModule(); +builder.Services.AddWorkflowsModule(); + +var app = builder.Build(); + +// Read the backend URL from the JS-injected client config (baked into _Host.cshtml). +var js = app.Services.GetRequiredService(); +var clientConfig = await js.InvokeAsync("getClientConfig"); +var apiUrl = clientConfig.GetProperty("apiUrl").GetString()!; +app.Services.GetRequiredService>().Value.Url = new Uri(apiUrl); + +var startupTaskRunner = app.Services.GetRequiredService(); +await startupTaskRunner.RunStartupTasksAsync(); + +await app.RunAsync(); diff --git a/src/Elsa.Studio.Wasm/_Imports.razor b/src/Elsa.Studio.Wasm/_Imports.razor new file mode 100644 index 0000000..535921f --- /dev/null +++ b/src/Elsa.Studio.Wasm/_Imports.razor @@ -0,0 +1,6 @@ +@using System.Net.Http +@using System.Net.Http.Json +@using Microsoft.AspNetCore.Components.Routing +@using Microsoft.AspNetCore.Components.Web +@using Microsoft.AspNetCore.Components.WebAssembly.Http +@using Microsoft.JSInterop diff --git a/src/Elsa.Studio.Wasm/wwwroot/appsettings.json b/src/Elsa.Studio.Wasm/wwwroot/appsettings.json new file mode 100644 index 0000000..b01d007 --- /dev/null +++ b/src/Elsa.Studio.Wasm/wwwroot/appsettings.json @@ -0,0 +1,5 @@ +{ + "Backend": { + "Url": "/elsa/api" + } +}