-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathServer.cs
More file actions
56 lines (46 loc) · 1.57 KB
/
Server.cs
File metadata and controls
56 lines (46 loc) · 1.57 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
using OpenRec_2.API;
namespace OpenRec_2;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
public static class Server
{
private static readonly List<IApi> ApiList =
[
new DefaultApi(),
new TestApi(),
new CharadesWordsApi(),
new AmplitudeApi(),
new ConfigV2Api(),
new VersionCheckApi()
];
public static async Task StartAsync(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
//builder.Logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Warning);
var app = builder.Build();
app.Run(async context =>
{
var path = context.Request.Path;
var method = context.Request.Method;
bool apiFufilled = false;
foreach (IApi api in ApiList)
{
if (path == api.GetUrl() && method == api.GetMethod())
{
context.Response.ContentType = "application/json";
await context.Response.WriteAsync(api.Response(context));
apiFufilled = true;
break;
}
}
if (!apiFufilled)
{
context.Response.StatusCode = StatusCodes.Status404NotFound;
await context.Response.WriteAsync("404 - Endpoint Not Found");
}
});
// asgfhosa ckjabvuciba bnc vbakuyfcp/al vchjnavboaiv ashgbc ajiakjb cyab gffff
await app.RunAsync();
}
}