2023-04-23 18:03:52 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Modules.Management;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Modules.Runtime;
|
|
|
|
|
using Elsa.Extensions;
|
2023-06-08 10:01:26 +00:00
|
|
|
using Elsa.Samples.AspNet.Onboarding.WorkflowServer.Workflows;
|
2023-04-23 18:03:52 +00:00
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
|
|
// Add services to the container.
|
|
|
|
|
builder.Services.AddElsa(elsa =>
|
|
|
|
|
{
|
|
|
|
|
// Add workflow.
|
|
|
|
|
elsa.AddWorkflow<OnboardingWorkflow>();
|
|
|
|
|
|
|
|
|
|
// Configure management feature to use EF Core.
|
2023-06-28 18:55:57 +00:00
|
|
|
elsa.UseWorkflowManagement(management => management.UseEntityFrameworkCore());
|
2023-04-23 18:03:52 +00:00
|
|
|
|
|
|
|
|
elsa.UseWorkflowRuntime(runtime =>
|
|
|
|
|
{
|
2023-06-28 18:55:57 +00:00
|
|
|
runtime.UseEntityFrameworkCore();
|
2023-04-23 18:03:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
elsa.UseIdentity(identity =>
|
|
|
|
|
{
|
|
|
|
|
identity.TokenOptions = options =>
|
|
|
|
|
{
|
2023-12-04 13:25:34 +00:00
|
|
|
options.SigningKey = "c7dc81876a782d502084763fa322429fca015941eac90ce8ca7ad95fc8752035";
|
2023-04-23 18:03:52 +00:00
|
|
|
options.AccessTokenLifetime = TimeSpan.FromDays(1);
|
|
|
|
|
};
|
2023-10-15 09:37:21 +00:00
|
|
|
|
|
|
|
|
identity.UseAdminUserProvider();
|
2023-04-23 18:03:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Expose API endpoints.
|
|
|
|
|
elsa.UseWorkflowsApi();
|
|
|
|
|
|
|
|
|
|
// Use default authentication (JWT + ApiKey).
|
|
|
|
|
elsa.UseDefaultAuthentication(auth => auth.UseAdminApiKey());
|
|
|
|
|
|
2023-12-04 13:25:34 +00:00
|
|
|
elsa.UseJavaScript();
|
|
|
|
|
|
2023-10-15 10:02:51 +00:00
|
|
|
// Enable SignalR for sending events to Elsa Studio for real-time updates.
|
|
|
|
|
elsa.UseRealTimeWorkflows();
|
|
|
|
|
|
|
|
|
|
// Use Webhooks feature.
|
2024-07-21 14:48:38 +00:00
|
|
|
elsa.UseWebhooks(webhooks => webhooks.ConfigureSinks = options => builder.Configuration.GetSection("Webhooks:Sinks").Bind(options));
|
2023-04-23 18:03:52 +00:00
|
|
|
});
|
|
|
|
|
|
2023-10-15 10:02:51 +00:00
|
|
|
builder.Services.AddHealthChecks();
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
|
builder.Services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().WithExposedHeaders("*")));
|
|
|
|
|
|
2023-04-23 18:03:52 +00:00
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
2023-10-15 10:02:51 +00:00
|
|
|
app.UseCors();
|
2023-04-23 18:03:52 +00:00
|
|
|
app.UseHttpsRedirection();
|
2023-10-15 10:02:51 +00:00
|
|
|
app.MapHealthChecks("/");
|
|
|
|
|
app.UseRouting();
|
2023-04-23 18:03:52 +00:00
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
app.UseWorkflowsApi();
|
2023-10-15 10:02:51 +00:00
|
|
|
app.UseJsonSerializationErrorHandler();
|
|
|
|
|
app.UseWorkflows();
|
|
|
|
|
app.UseWorkflowsSignalRHubs();
|
2023-04-23 18:03:52 +00:00
|
|
|
app.Run();
|