2023-05-16 18:03:12 +00:00
|
|
|
using Elsa;
|
2023-06-28 20:46:58 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Modules.Identity;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Modules.Management;
|
|
|
|
|
using Elsa.EntityFrameworkCore.Modules.Runtime;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Extensions;
|
2023-05-01 10:06:51 +00:00
|
|
|
using Elsa.Http.Handlers;
|
2023-02-15 11:09:45 +00:00
|
|
|
using Elsa.JavaScript.Options;
|
2023-06-28 20:44:51 +00:00
|
|
|
using Elsa.MongoDb.Extensions;
|
2023-04-16 22:11:58 +00:00
|
|
|
using Elsa.WorkflowServer.Web;
|
2022-05-26 10:47:31 +00:00
|
|
|
|
2023-05-16 18:03:12 +00:00
|
|
|
EndpointSecurityOptions.DisableSecurity();
|
|
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
var services = builder.Services;
|
2022-08-31 13:47:10 +00:00
|
|
|
var configuration = builder.Configuration;
|
|
|
|
|
var identitySection = configuration.GetSection("Identity");
|
2023-01-02 21:24:05 +00:00
|
|
|
var identityTokenSection = identitySection.GetSection("Tokens");
|
2022-08-27 19:58:22 +00:00
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
// Add Elsa services.
|
|
|
|
|
services
|
2022-05-26 14:07:01 +00:00
|
|
|
.AddElsa(elsa => elsa
|
2023-01-02 21:24:05 +00:00
|
|
|
.AddActivitiesFrom<Program>()
|
2023-06-03 10:28:10 +00:00
|
|
|
.UseFluentStorageProvider()
|
2023-04-16 22:11:58 +00:00
|
|
|
.AddTypeAlias<ApiResponse<User>>("ApiResponse[User]")
|
2022-12-09 11:25:39 +00:00
|
|
|
.UseIdentity(identity =>
|
2022-08-31 13:47:10 +00:00
|
|
|
{
|
2023-06-28 20:46:58 +00:00
|
|
|
identity.UseEntityFrameworkCore();
|
2023-03-26 21:53:17 +00:00
|
|
|
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));
|
2022-08-31 13:47:10 +00:00
|
|
|
})
|
2022-12-30 12:11:29 +00:00
|
|
|
.UseDefaultAuthentication()
|
2023-04-16 22:11:58 +00:00
|
|
|
.UseWorkflowManagement(management =>
|
|
|
|
|
{
|
2023-06-28 20:46:58 +00:00
|
|
|
management.UseEntityFrameworkCore();
|
2023-04-16 22:11:58 +00:00
|
|
|
management.AddVariableType<ApiResponse<User>>("Api");
|
|
|
|
|
management.AddVariableType<User>("Api");
|
|
|
|
|
management.AddVariableType<Support>("Api");
|
|
|
|
|
})
|
2022-11-23 21:36:43 +00:00
|
|
|
.UseWorkflowRuntime(runtime =>
|
2022-09-07 15:28:36 +00:00
|
|
|
{
|
2023-06-28 20:46:58 +00:00
|
|
|
runtime.UseEntityFrameworkCore();
|
|
|
|
|
runtime.UseDefaultRuntime(dr => dr.UseEntityFrameworkCore());
|
|
|
|
|
runtime.UseExecutionLogRecords(e => e.UseEntityFrameworkCore());
|
2023-01-02 21:24:05 +00:00
|
|
|
runtime.UseAsyncWorkflowStateExporter();
|
2023-01-04 14:28:28 +00:00
|
|
|
runtime.UseMassTransitDispatcher();
|
2022-09-07 15:28:36 +00:00
|
|
|
})
|
2023-05-16 08:03:55 +00:00
|
|
|
.UseEnvironments(environments => environments.EnvironmentsOptions = options => configuration.GetSection("Environments").Bind(options))
|
2022-08-11 18:04:47 +00:00
|
|
|
.UseScheduling()
|
2023-01-10 13:32:14 +00:00
|
|
|
.UseWorkflowsApi(api => api.AddFastEndpointsAssembly<Program>())
|
2022-05-26 15:05:36 +00:00
|
|
|
.UseJavaScript()
|
|
|
|
|
.UseLiquid()
|
2023-05-01 10:06:51 +00:00
|
|
|
.UseHttp(http => http.HttpEndpointAuthorizationHandler = sp => sp.GetRequiredService<AllowAnonymousHttpEndpointAuthorizationHandler>())
|
2023-04-18 20:14:18 +00:00
|
|
|
.UseEmail(email => email.ConfigureOptions = options => configuration.GetSection("Smtp").Bind(options))
|
2023-06-28 20:44:51 +00:00
|
|
|
.UseMongoDb(configuration.GetConnectionString("MongoDb")!, options => configuration.GetSection("MongoDb").Bind(options))
|
2022-12-20 11:13:53 +00:00
|
|
|
);
|
2022-05-26 10:47:31 +00:00
|
|
|
|
2023-02-15 11:09:45 +00:00
|
|
|
services.Configure<JintOptions>(options => options.AllowClrAccess = true);
|
2022-05-26 10:47:31 +00:00
|
|
|
services.AddHealthChecks();
|
|
|
|
|
services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()));
|
|
|
|
|
|
|
|
|
|
// Configure middleware pipeline.
|
|
|
|
|
var app = builder.Build();
|
2022-07-26 21:30:42 +00:00
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
|
|
|
|
|
// CORS.
|
|
|
|
|
app.UseCors();
|
|
|
|
|
|
|
|
|
|
// Health checks.
|
|
|
|
|
app.MapHealthChecks("/");
|
|
|
|
|
|
2022-07-21 14:18:42 +00:00
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
2023-04-17 13:23:05 +00:00
|
|
|
// Elsa API endpoints for designer.
|
2022-12-30 12:11:29 +00:00
|
|
|
app.UseWorkflowsApi();
|
2023-04-17 13:23:05 +00:00
|
|
|
|
|
|
|
|
// Captures unhandled exceptions and returns a JSON response.
|
2022-05-26 10:47:31 +00:00
|
|
|
app.UseJsonSerializationErrorHandler();
|
2023-04-17 13:23:05 +00:00
|
|
|
|
|
|
|
|
// Elsa HTTP Endpoint activities
|
2022-12-30 12:11:29 +00:00
|
|
|
app.UseWorkflows();
|
2022-05-26 10:47:31 +00:00
|
|
|
|
|
|
|
|
// Run.
|
2022-08-31 13:47:10 +00:00
|
|
|
app.Run();
|