-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
30 lines (25 loc) · 1.05 KB
/
Copy pathProgram.cs
File metadata and controls
30 lines (25 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using RuleEngine.App.Models;
using System.Text.Json;
using RuleEngine.App.Core;
using RuleEngine.App;
var builder = WebApplication.CreateBuilder(args);
var rulesFilePath = builder.Configuration["RulesV1FilePath"];
var json = File.ReadAllText(rulesFilePath ?? string.Empty);
var rules = JsonSerializer.Deserialize<List<Rule>>(json) ?? [];
builder.Services.AddSingleton(rules.Cast<BaseRule>().ToList());
builder.Services.AddScoped<RequestHandlerV1>();
builder.Services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.WithMethods("POST", "GET")
.WithHeaders("Content-Type", "Accept"));
});
var app = builder.Build();
app.UseCors("CorsPolicy");
app.UseMiddleware<ExceptionHandlerMiddleware>();
app.UseCors();
app.MapGet("/v1/rules", () => Results.Ok(rules));
app.MapPost("/v1/evaluate-rule", async (HttpContext httpContext, RequestHandlerV1 requestHandler) =>
await requestHandler.HandleRuleEvaluationRequest(httpContext));
app.Run();