2022-04-29 12:40:25 +00:00
|
|
|
using Elsa.Extensions;
|
|
|
|
|
using Elsa.Jobs.Extensions;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Http.Extensions;
|
2022-12-09 11:24:05 +00:00
|
|
|
using Elsa.Identity;
|
|
|
|
|
using Elsa.Identity.Extensions;
|
|
|
|
|
using Elsa.Identity.Options;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.JavaScript.Extensions;
|
2022-12-09 11:24:05 +00:00
|
|
|
using Elsa.Labels.Extensions;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Liquid.Extensions;
|
2022-12-30 12:11:29 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Modules.ActivityDefinitions;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Modules.Labels;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Modules.Runtime;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Sqlite.Modules.ActivityDefinitions;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Sqlite.Modules.Labels;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Sqlite.Modules.Runtime;
|
2022-12-09 11:24:05 +00:00
|
|
|
using Elsa.Requirements;
|
2022-08-11 10:45:07 +00:00
|
|
|
using Elsa.Scheduling.Extensions;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Workflows.Core;
|
|
|
|
|
using Elsa.Workflows.Runtime.Extensions;
|
2022-12-09 11:24:05 +00:00
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2022-04-29 12:40:25 +00:00
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
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();
|
|
|
|
|
var identitySection = configuration.GetSection("Identity");
|
|
|
|
|
identitySection.Bind(identityOptions);
|
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 =>
|
|
|
|
|
{
|
|
|
|
|
identity.CreateDefaultUser = true;
|
2022-12-30 12:11:29 +00:00
|
|
|
identity.IdentityOptions = identityOptions;
|
2022-12-09 11:24:05 +00:00
|
|
|
})
|
2022-12-30 12:11:29 +00:00
|
|
|
.UseDefaultAuthentication()
|
2022-12-09 11:24:05 +00:00
|
|
|
.UseWorkflowRuntime(runtime => { runtime.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)); })
|
|
|
|
|
.UseLabels(labels => labels.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)))
|
|
|
|
|
.UseActivityDefinitions(feature => feature.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())));
|
2022-04-29 12:40:25 +00:00
|
|
|
|
|
|
|
|
// Razor Pages.
|
|
|
|
|
services.AddRazorPages();
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
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-13 20:49:38 +00:00
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
|
{
|
|
|
|
|
endpoints.MapFallbackToPage("/Index");
|
|
|
|
|
});
|
2022-04-29 12:40:25 +00:00
|
|
|
|
2022-12-20 11:13:53 +00:00
|
|
|
app.MapRazorPages();
|
2022-04-29 12:40:25 +00:00
|
|
|
app.Run();
|