-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
60 lines (53 loc) · 1.62 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
using System.Text.Json.Serialization;
using Coflnet.Auth;
using Coflnet.Connections.Services;
using Coflnet.Core;
using FirebaseAdmin;
using Google.Apis.Auth.OAuth2;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<SearchService>();
builder.Services.AddSingleton<PersonService>();
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddControllers().AddJsonOptions(o =>
{
o.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});
builder.AddCoflAuthService();
builder.Services.AddCoflnetCore();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
var app = builder.Build();
app.UseRouting();
app.UseCoflnetCore();
app.UseCors("AllowAll");
// log every request
app.Use(async (context, next) =>
{
Console.WriteLine($"Request: {context.Request.Path}");
await next();
var responseCode = context.Response.StatusCode;
Console.WriteLine($"Response: {responseCode}");
});
app.UseCoflAuthService();
app.MapControllers();
var googleConfigpath = app.Configuration["GOOGLE_APPLICATION_CREDENTIALS"];
if (googleConfigpath == null)
app.Logger.LogWarning("GOOGLE_APPLICATION_CREDENTIALS not set, not initializing Firebase");
else
{
var credentials = await GoogleCredential.FromFileAsync(googleConfigpath, default);
FirebaseApp.Create(new AppOptions()
{
Credential = credentials
});
}
app.Run();