Compare commits

..

No commits in common. "e5300dd6c20da96061eb94822b704b59fc891334" and "3c0926fdf35acee9272a3a811a2545ea00d39170" have entirely different histories.

View File

@ -5,17 +5,10 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.DependencyInjection;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using System.Text.Json;
using AcaMate.Common.Models; using AcaMate.Common.Models;
using AcaMate.V1.Services; using AcaMate.V1.Services;
using AcaMate.Common.Data; using AcaMate.Common.Data;
using AcaMate.V1.Controllers; using AcaMate.V1.Controllers;
using AcaMate.V1.Models;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -78,37 +71,6 @@ builder.Services.AddAuthentication(options =>
}); });
// JWT 설정부 끝 // JWT 설정부 끝
// PUSH 설정부
// 설정 바인딩 (appsettings.json의 "ApnsPushService" 섹션)
builder.Services.Configure<PushFileSetting>(builder.Configuration.GetSection("PushFileSetting"));
// HttpClientFactory를 이용한 ApnsPushService 등록 (핸들러에 인증서 추가)
builder.Services.AddHttpClient<IApnsPushService, ApnsPushService>(client =>
{
var settings = builder.Configuration.GetSection("PushFileSetting").Get<PushFileSetting>();
client.BaseAddress = new Uri(settings.uri);
client.Timeout = TimeSpan.FromSeconds(60);
})
.ConfigurePrimaryHttpMessageHandler(() =>
{
var config = builder.Configuration.GetSection("PushFileSetting").Get<PushFileSetting>();
var handler = new HttpClientHandler();
// using var reader = new StreamReader(config.p12PWPath, new UTF8Encoding(false));
// var json = reader.ReadToEndAsync();
// p12PWPath 파일에서 비밀번호 읽어오기 (예시: JSON {"Password": "비밀번호"})
var json = File.ReadAllText(config.p12PWPath);
var keys = JsonSerializer.Deserialize<Dictionary<string, string>>(json);
var certificate = new X509Certificate2(config.p12Path, keys["Password"]);
handler.ClientCertificates.Add(certificate);
handler.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
return handler;
});
// InMemoryPushQueue와 백그라운드 서비스 등록
builder.Services.AddSingleton<IPushQueue, InMemoryPushQueue>();
builder.Services.AddHostedService<PushBackgroundService>();
// PUSH 설정부 끝
builder.Services.AddControllers(); builder.Services.AddControllers();
// 여기다가 API 있는 컨트롤러들 AddScoped 하면 되는건가? // 여기다가 API 있는 컨트롤러들 AddScoped 하면 되는건가?
@ -152,7 +114,7 @@ else
// 로컬 테스트 위한 부분 (올릴때는 꺼두기) // 로컬 테스트 위한 부분 (올릴때는 꺼두기)
// builder.WebHost.UseUrls("http://0.0.0.0:5144"); builder.WebHost.UseUrls("http://0.0.0.0:5144");
///// ===== builder 설정 부 ===== ///// ///// ===== builder 설정 부 ===== /////
@ -172,7 +134,7 @@ else
} }
// 로컬 테스트 위한 부분 (올릴떄는 켜두기) // 로컬 테스트 위한 부분 (올릴떄는 켜두기)
app.UseHttpsRedirection(); // app.UseHttpsRedirection();
app.UseRouting(); app.UseRouting();
// app.MapControllers(); // app.MapControllers();