2023-12-27 19:30:33 +00:00
|
|
|
using Elsa.ServerAndStudio.Web.Extensions;
|
2022-12-31 15:16:43 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Extensions;
|
2023-01-14 11:22:38 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Modules.Management;
|
2022-12-30 12:11:29 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Modules.Runtime;
|
2023-10-07 21:24:56 +00:00
|
|
|
using Elsa.Extensions;
|
2023-01-14 11:22:38 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2022-04-29 12:40:25 +00:00
|
|
|
|
2024-01-12 07:47:41 +00:00
|
|
|
const bool useMassTransit = true;
|
|
|
|
|
|
2022-04-29 12:40:25 +00:00
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
2023-01-06 19:00:03 +00:00
|
|
|
builder.WebHost.UseStaticWebAssets();
|
2022-04-29 12:40:25 +00:00
|
|
|
var services = builder.Services;
|
2022-12-09 11:24:05 +00:00
|
|
|
var configuration = builder.Configuration;
|
2022-12-30 12:11:29 +00:00
|
|
|
var sqliteConnectionString = configuration.GetConnectionString("Sqlite")!;
|
2022-12-09 11:24:05 +00:00
|
|
|
var identitySection = configuration.GetSection("Identity");
|
2023-01-01 21:54:07 +00:00
|
|
|
var identityTokenSection = identitySection.GetSection("Tokens");
|
2022-04-29 12:40:25 +00:00
|
|
|
|
2022-05-23 14:12:21 +00:00
|
|
|
// Add Elsa services.
|
2022-04-29 12:40:25 +00:00
|
|
|
services
|
2024-01-12 07:47:41 +00:00
|
|
|
.AddElsa(elsa =>
|
|
|
|
|
{
|
|
|
|
|
elsa
|
|
|
|
|
.UseSasTokens()
|
|
|
|
|
.UseIdentity(identity =>
|
|
|
|
|
{
|
|
|
|
|
identity.IdentityOptions = options => identitySection.Bind(options);
|
|
|
|
|
identity.TokenOptions = options => identityTokenSection.Bind(options);
|
|
|
|
|
identity.UseConfigurationBasedUserProvider(options => identitySection.Bind(options));
|
|
|
|
|
identity.UseConfigurationBasedApplicationProvider(options => identitySection.Bind(options));
|
|
|
|
|
identity.UseConfigurationBasedRoleProvider(options => identitySection.Bind(options));
|
|
|
|
|
})
|
|
|
|
|
.UseDefaultAuthentication()
|
|
|
|
|
.UseWorkflowManagement(management => management.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)))
|
|
|
|
|
.UseWorkflowRuntime(runtime => runtime.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)))
|
|
|
|
|
.UseScheduling()
|
|
|
|
|
.UseJavaScript(options => options.AllowClrAccess = true)
|
|
|
|
|
.UseLiquid()
|
|
|
|
|
.UseCSharp()
|
|
|
|
|
.UsePython()
|
|
|
|
|
.UseHttp(http => http.ConfigureHttpOptions = options => configuration.GetSection("Http").Bind(options))
|
|
|
|
|
.UseEmail(email => email.ConfigureOptions = options => configuration.GetSection("Smtp").Bind(options))
|
|
|
|
|
.UseWebhooks(webhooks => webhooks.WebhookOptions = options => builder.Configuration.GetSection("Webhooks").Bind(options))
|
|
|
|
|
.UseWorkflowsApi()
|
|
|
|
|
.UseRealTimeWorkflows()
|
|
|
|
|
.AddActivitiesFrom<Program>()
|
|
|
|
|
.AddWorkflowsFrom<Program>();
|
|
|
|
|
|
|
|
|
|
if (useMassTransit)
|
2022-12-09 11:24:05 +00:00
|
|
|
{
|
2024-01-12 07:47:41 +00:00
|
|
|
elsa.UseMassTransit();
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-05-26 10:47:31 +00:00
|
|
|
|
2022-12-09 11:24:05 +00:00
|
|
|
services.AddHealthChecks();
|
2023-05-15 09:38:18 +00:00
|
|
|
|
2023-05-28 18:31:42 +00:00
|
|
|
services.AddCors(cors => cors.Configure(configuration.GetSection("CorsPolicy")));
|
2022-04-29 12:40:25 +00:00
|
|
|
|
|
|
|
|
// Razor Pages.
|
2023-01-14 11:22:38 +00:00
|
|
|
services.AddRazorPages(options => options.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute()));
|
2022-04-29 12:40:25 +00:00
|
|
|
|
|
|
|
|
// Configure middleware pipeline.
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
|
if (!app.Environment.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseExceptionHandler("/Error");
|
|
|
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
|
|
|
app.UseHsts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
2023-10-18 23:03:55 +00:00
|
|
|
app.UseBlazorFrameworkFiles();
|
2023-05-02 09:03:34 +00:00
|
|
|
app.MapHealthChecks("/health");
|
2023-06-08 08:26:37 +00:00
|
|
|
app.UseRouting();
|
2023-01-14 11:22:38 +00:00
|
|
|
app.UseCors();
|
2022-04-29 12:40:25 +00:00
|
|
|
app.UseStaticFiles();
|
2022-12-09 11:24:05 +00:00
|
|
|
app.UseAuthentication();
|
2022-04-29 12:40:25 +00:00
|
|
|
app.UseAuthorization();
|
2022-12-30 12:11:29 +00:00
|
|
|
app.UseWorkflowsApi();
|
|
|
|
|
app.UseWorkflows();
|
2023-10-18 23:03:55 +00:00
|
|
|
app.UseWorkflowsSignalRHubs();
|
|
|
|
|
app.MapFallbackToPage("/_Host");
|
2023-12-27 19:17:55 +00:00
|
|
|
app.Run();
|