-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
202 lines (163 loc) · 5.2 KB
/
Program.cs
File metadata and controls
202 lines (163 loc) · 5.2 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using FluentValidation;
using Microsoft.AspNetCore.Diagnostics;
using System.Text.Json.Serialization;
using Train.Solver.AdminAPI.Endpoints;
using Train.Solver.Common.Extensions;
using Train.Solver.Common.Serialization;
using Train.Solver.Common.Swagger;
using Train.Solver.Data.Npgsql.Extensions;
using Train.Solver.Infrastructure.DependencyInjection;
using Train.Solver.Infrastructure.Extensions;
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
builder.Configuration
.SetBasePath(builder.Environment.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.Local.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables();
builder.Services.ConfigureHttpJsonOptions(options =>
{
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
options.SerializerOptions.Converters.Add(new BigIntegerConverter());
});
builder.Services.Configure<Microsoft.AspNetCore.Mvc.JsonOptions>(options =>
{
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
options.JsonSerializerOptions.Converters.Add(new BigIntegerConverter());
});
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new() { Title = "Train Solver Admin API" });
c.EnableAnnotations();
c.CustomSchemaIds(i => i.FriendlyId());
c.SupportNonNullableReferenceTypes();
c.SchemaFilter<BigIntegerSchemaFilter>();
});
builder.Services.AddValidatorsFromAssemblyContaining<Program>();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddHttpClient();
builder.Services
.AddTrainSolver(builder.Configuration)
.WithCoreServices()
.WithNpgsqlRepositories();
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(policy =>
{
policy.AllowAnyHeader();
policy.AllowAnyMethod();
policy.AllowAnyOrigin();
});
});
var app = builder.Build();
app.UseExceptionHandler(errorApp =>
{
errorApp.Run(async context =>
{
context.Response.StatusCode = StatusCodes.Status500InternalServerError;
context.Response.ContentType = "application/json";
var exceptionHandlerPathFeature = context.Features.Get<IExceptionHandlerPathFeature>();
var ex = exceptionHandlerPathFeature?.Error;
Console.WriteLine($"[UNHANDLED EXCEPTION]: {ex}");
var response = new
{
error = "An unexpected error occurred."
};
await context.Response.WriteAsJsonAsync(response);
});
});
app.UseCors();
app.MapGroup("/api")
.MapNetworkEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Network");
app.MapGroup("/api")
.MapSignerAgentEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Signer Agent");
app.MapGroup("/api")
.MapWalletEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Wallet");
app.MapGroup("/api")
.MapTrustedWalletEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Trusted Wallet");
app.MapGroup("/api")
.MapFeeEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Fee");
app.MapGroup("/api")
.MapWebhookEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Webhook");
app.MapGroup("/api")
.MapOrderEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Order");
app.MapGroup("/api")
.MapRouteEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Route");
app.MapGroup("/api")
.MapRateProviderEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Rate Provider");
app.MapGroup("/api")
.MapNetworkTypeEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Network Type");
app.MapGroup("/api")
.MapTokenPriceEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Token Price");
app.MapGroup("/api")
.MapOrderMetricEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Order Metric");
app.MapGroup("/api")
.MapRebalanceEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Rebalance");
app.MapGroup("/api")
.MapNodeProviderEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Node Provider");
app.MapGroup("/api")
.MapTransactionBuilderEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Transaction Builder");
app.MapGroup("/api")
.MapTransactionLookupEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Transaction Lookup");
app.MapGet("/api/health", () => Results.Ok())
.WithTags("Health");
app.MapGroup("/api")
.MapHealthEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Health");
app.MapGroup("/api")
.MapInfrastructureEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Infrastructure");
app.MapGroup("/api")
.MapWorkflowManagementEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Workflow Management");
app.MapGroup("/api")
.MapTestEndpoints()
.RequireRateLimiting("Fixed")
.WithTags("Test");
app.MapGroup("/api")
.MapGet("/ping", () => Results.Ok())
.WithTags("System")
.Produces(StatusCodes.Status200OK);
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Train Solver Admin API");
c.DisplayRequestDuration();
});
await app.RunAsync();