-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
62 lines (51 loc) · 2.44 KB
/
Program.cs
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
using Discord;
using Discord.Rest;
using StackExchange.Redis;
using TED.API.Middleware;
using TED.API.Services;
namespace TED.API
{
public static class Program
{
public static async Task Main(string[] args)
{
var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.AddCors(options =>
{
// half of these are not necessary at all and don't even make sense
options.AddPolicy("CorsPolicy",
builder => builder.WithOrigins([
"http://localhost:3001",
"http://localhost:3000",
"https://api.liege.dev",
"http://api.liege.dev",
"https://ted.liege.dev",
"http://ted.liege.dev",
"https://discord.com",
"https://ted.liege"])
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
builder.Services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
});
// add discord rest client to services
builder.Services.AddSingleton<DiscordRestClient>();
builder.Services.AddSingleton<IConnectionMultiplexer>(await ConnectionMultiplexer.ConnectAsync(Environment.GetEnvironmentVariable("REDIS_CONNECT") ?? "localhost"));
builder.Services.AddHttpClient();
var tokenRefreshService = new TokenRefreshService();
var app = builder.Build();
app.UseCors("CorsPolicy");
// new discord rest client
await app.Services.GetRequiredService<DiscordRestClient>().LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("BOT_TOKEN"));
app.UseMiddleware<ParameterValidationMiddleware>();
app.UseMiddleware<RateLimitMiddleware>();
// app.UseMiddleware<AuthenticationMiddleware>();
app.MapControllers();
await app.RunAsync();
}
}
}