2022-12-31 15:16:43 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Extensions;
|
2022-04-29 12:40:25 +00:00
|
|
|
using Elsa.Extensions;
|
2022-12-09 11:24:05 +00:00
|
|
|
using Elsa.Identity;
|
|
|
|
|
using Elsa.Identity.Options;
|
2022-12-30 12:11:29 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Modules.Labels;
|
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;
|
2022-12-09 11:24:05 +00:00
|
|
|
using Elsa.Requirements;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2023-01-14 11:22:38 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
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 identityOptions = new IdentityOptions();
|
2023-01-01 21:54:07 +00:00
|
|
|
var identityTokenOptions = new IdentityTokenOptions();
|
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-12-09 11:24:05 +00:00
|
|
|
identitySection.Bind(identityOptions);
|
2023-01-01 21:54:07 +00:00
|
|
|
identityTokenSection.Bind(identityTokenOptions);
|
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
|
2022-05-26 15:05:36 +00:00
|
|
|
.AddElsa(elsa => elsa
|
|
|
|
|
.UseWorkflows()
|
2022-12-30 12:11:29 +00:00
|
|
|
.UseWorkflowsApi()
|
2022-12-09 11:24:05 +00:00
|
|
|
.UseIdentity(identity =>
|
|
|
|
|
{
|
2022-12-30 12:11:29 +00:00
|
|
|
identity.IdentityOptions = identityOptions;
|
2023-01-01 21:54:07 +00:00
|
|
|
identity.TokenOptions = identityTokenOptions;
|
2022-12-09 11:24:05 +00:00
|
|
|
})
|
2022-12-30 12:11:29 +00:00
|
|
|
.UseDefaultAuthentication()
|
2023-01-14 11:22:38 +00:00
|
|
|
.UseWorkflowManagement(management => management.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)))
|
2023-01-05 14:10:55 +00:00
|
|
|
.UseWorkflowRuntime(runtime =>
|
|
|
|
|
{
|
|
|
|
|
runtime.UseDefaultRuntime(dr => dr.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)));
|
|
|
|
|
runtime.UseExecutionLogRecords(e => e.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)));
|
2023-01-14 11:22:38 +00:00
|
|
|
runtime.UseAsyncWorkflowStateExporter();
|
2023-01-05 14:10:55 +00:00
|
|
|
})
|
2022-12-09 11:24:05 +00:00
|
|
|
.UseLabels(labels => labels.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)))
|
2022-08-11 10:45:07 +00:00
|
|
|
.UseJobs()
|
|
|
|
|
.UseScheduling()
|
2022-05-26 15:05:36 +00:00
|
|
|
.UseJavaScript()
|
|
|
|
|
.UseLiquid()
|
|
|
|
|
.UseHttp()
|
2022-12-20 11:13:53 +00:00
|
|
|
);
|
2022-05-26 10:47:31 +00:00
|
|
|
|
2022-12-09 11:24:05 +00:00
|
|
|
services.AddHealthChecks();
|
|
|
|
|
services.AddHttpContextAccessor();
|
|
|
|
|
services.AddSingleton<IAuthorizationHandler, LocalHostRequirementHandler>();
|
|
|
|
|
services.AddAuthorization(options => options.AddPolicy(IdentityPolicyNames.SecurityRoot, policy => policy.AddRequirements(new LocalHostRequirement())));
|
2023-01-14 11:22:38 +00:00
|
|
|
services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()));
|
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-01-14 11:22:38 +00:00
|
|
|
app.UseCors();
|
2022-04-29 12:40:25 +00:00
|
|
|
app.UseStaticFiles();
|
|
|
|
|
app.UseRouting();
|
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();
|
2022-12-20 11:13:53 +00:00
|
|
|
app.MapRazorPages();
|
2022-04-29 12:40:25 +00:00
|
|
|
app.Run();
|