Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
142 lines (112 loc) · 3.9 KB
/
Copy pathProgram.cs
File metadata and controls
142 lines (112 loc) · 3.9 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
<<<<<<< HEAD
using System.Text;
=======
using System.Text;
>>>>>>> fc15b791a7b488ee839afa2b10116487d7d9f5be
using Chatup.Services;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using MongoDB.Driver;
<<<<<<< HEAD
using sib_api_v3_sdk.Client;
=======
using Scalar.AspNetCore;
>>>>>>> fc15b791a7b488ee839afa2b10116487d7d9f5be
using StackExchange.Redis;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
<<<<<<< HEAD
var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("MongoDb"));
builder.Services.AddSingleton<IMongoDatabase>(mongoClient.GetDatabase("chatup"));
var redis = ConnectionMultiplexer.Connect(builder.Configuration.GetConnectionString("Redis")!);
builder.Services.AddSingleton<IConnectionMultiplexer>(redis);
// Brevo
Configuration.Default.ApiKey.Add("api-key", builder.Configuration["Brevo:ApiKey"]);
builder.Services.AddCors(options =>
{
options.AddPolicy("CorsPolicy", policy =>
{
policy
.WithOrigins("http://localhost:5173")
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
});
=======
var mongoClient = new MongoClient(builder.Configuration.GetConnectionString("MongoDB"));
builder.Services.AddSingleton<IMongoDatabase>(mongoClient.GetDatabase("chatup"));
var redis = ConnectionMultiplexer.Connect(builder.Configuration.GetConnectionString("Redis")!);
builder.Services.AddSingleton<IConnectionMultiplexer>(redis);
builder.Services.AddScoped<AuthService>();
builder.Services.AddControllers();
builder.Services.AddScoped<UserService>();
>>>>>>> fc15b791a7b488ee839afa2b10116487d7d9f5be
var jwtSettings = builder.Configuration.GetSection("JwtSettings");
var key = Encoding.ASCII.GetBytes(jwtSettings["SecretKey"]!);
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = true,
ValidIssuer = jwtSettings["Issuer"],
ValidateAudience = true,
ValidAudience = jwtSettings["Audience"]
};
<<<<<<< HEAD
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
var accessToken = context.Request.Query["access_token"];
var path = context.HttpContext.Request.Path;
if (!string.IsNullOrEmpty(accessToken) &&
path.StartsWithSegments("/hubs/chat"))
{
context.Token = accessToken;
}
return Task.CompletedTask;
}
};
});
builder.Services.AddScoped<AuthService>();
builder.Services.AddScoped<UserService>();
builder.Services.AddScoped<ConversationService>();
builder.Services.AddScoped<MessageService>();
builder.Services.AddControllers();
builder.Services.AddSignalR();
=======
});
>>>>>>> fc15b791a7b488ee839afa2b10116487d7d9f5be
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.MapScalarApiReference(options =>
{
options.WithOpenApiRoutePattern("/swagger/v1/swagger.json");
});
}
<<<<<<< HEAD
app.UseCors("CorsPolicy");
// app.UseHttpsRedirection();
=======
app.UseHttpsRedirection();
>>>>>>> fc15b791a7b488ee839afa2b10116487d7d9f5be
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
<<<<<<< HEAD
app.MapHub<Chatup.Hubs.ChatHub>("/hubs/chat");
app.Run();
=======
app.Run();
>>>>>>> fc15b791a7b488ee839afa2b10116487d7d9f5be