Skip to content

Commit

Permalink
Update RouteTable with HTTP Endpoint bookmarks at application startup
Browse files Browse the repository at this point in the history
Fixes #4405
  • Loading branch information
sfmskywalker committed Sep 9, 2023
1 parent 4a6872d commit 0fb936e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@
<PackageReference Include="Open.Linq.AsyncExtensions" Version="1.2.0" />
</ItemGroup>


</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using Elsa.Activities.Http.Scripting.JavaScript;
using Elsa.Activities.Http.Scripting.Liquid;
using Elsa.Activities.Http.Services;
using Elsa.Activities.Http.StartupTasks;
using Elsa.Events;
using Elsa.Options;
using Elsa.Runtime;
using Elsa.Scripting.JavaScript.Providers;
using Elsa.Scripting.Liquid.Extensions;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -65,6 +67,7 @@ public static ElsaOptionsBuilder AddHttpServices(this ElsaOptionsBuilder options
.AddNotificationHandlers(typeof(ConfigureJavaScriptEngine))
.AddLiquidFilter<SignalUrlFilter>("signal_url")
.AddJavaScriptTypeDefinitionProvider<HttpTypeDefinitionProvider>()
.AddStartupTask<UpdateRouteTableWithBookmarks>()

.AddMemoryCache()
.AddDataProtection();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Threading;
using System.Threading.Tasks;
using Elsa.Activities.Http.Bookmarks;
using Elsa.Activities.Http.Contracts;
using Elsa.Activities.Http.Extensions;
using Elsa.Services;
using Open.Linq.AsyncExtensions;

namespace Elsa.Activities.Http.StartupTasks;

/// <summary>
/// A startup task that updates the route table with bookmarks. Triggers are already processed at startup.
/// </summary>
public class UpdateRouteTableWithBookmarks : IStartupTask
{
private readonly IBookmarkFinder _bookmarkFinder;
private readonly IRouteTable _routeTable;

public UpdateRouteTableWithBookmarks(IBookmarkFinder bookmarkFinder, IRouteTable routeTable)
{
_bookmarkFinder = bookmarkFinder;
_routeTable = routeTable;
}

public int Order => 1000;

public async Task ExecuteAsync(CancellationToken cancellationToken = default)
{
// Find all HTTP endpoint bookmarks.
var bookmarks = await _bookmarkFinder.FindBookmarksByTypeAsync<HttpEndpointBookmark>(cancellationToken: cancellationToken).ToList();

// Add them to the route table.
_routeTable.AddRoutes(bookmarks);
}
}
2 changes: 1 addition & 1 deletion src/designer/elsa-workflows-studio/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<body>

<elsa-studio-root server-url="https://localhost:15265" monaco-lib-path="build/assets/js/monaco-editor/min" culture="en-US" config="build/assets/designer.config.json">
<elsa-studio-root server-url="https://localhost:11000" monaco-lib-path="build/assets/js/monaco-editor/min" culture="en-US" config="build/assets/designer.config.json">
<!-- The root dashboard component -->
<elsa-studio-dashboard></elsa-studio-dashboard>

Expand Down

0 comments on commit 0fb936e

Please sign in to comment.