forked from AcaMate/AcaMate_API
[✨] Front 빌드 테스트
This commit is contained in:
parent
5ab4940b5f
commit
d9166469f7
22
Program.cs
22
Program.cs
|
@ -4,6 +4,7 @@ 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.FileProviders;
|
||||||
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
@ -23,6 +24,7 @@ using Back.Program.Services.V1;
|
||||||
using Back.Program.Services.V1.Interfaces;
|
using Back.Program.Services.V1.Interfaces;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
|
||||||
|
@ -174,6 +176,7 @@ else
|
||||||
///// ===== builder 설정 부 ===== /////
|
///// ===== builder 설정 부 ===== /////
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
string staticRoot;
|
||||||
|
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
@ -181,11 +184,13 @@ if (app.Environment.IsDevelopment())
|
||||||
// app.UseSwaggerUI();
|
// app.UseSwaggerUI();
|
||||||
app.UseCustomSwaggerUI();
|
app.UseCustomSwaggerUI();
|
||||||
app.UseDeveloperExceptionPage(); // 좀더 자세한 예외 정보 제공
|
app.UseDeveloperExceptionPage(); // 좀더 자세한 예외 정보 제공
|
||||||
|
staticRoot = Path.Combine(Directory.GetCurrentDirectory(), "publish", "debug", "wwwroot");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
app.UseExceptionHandler("/error");
|
app.UseExceptionHandler("/error");
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
|
staticRoot = Path.Combine(Directory.GetCurrentDirectory(), "publish", "release", "wwwroot");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 로컬 테스트 위한 부분 (올릴떄는 켜두기)
|
// 로컬 테스트 위한 부분 (올릴떄는 켜두기)
|
||||||
|
@ -198,14 +203,31 @@ app.UseMiddleware<APIHeaderMiddleware>(
|
||||||
(object)new string[] { "iOS_AM_Connect_Key", "And_AM_Connect_Key", "Web_AM_Connect_Key" }
|
(object)new string[] { "iOS_AM_Connect_Key", "And_AM_Connect_Key", "Web_AM_Connect_Key" }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// app.UseBlazorFrameworkFiles();
|
||||||
|
// app.UseStaticFiles();
|
||||||
|
|
||||||
|
app.UseStaticFiles(new StaticFileOptions
|
||||||
|
{
|
||||||
|
FileProvider = new PhysicalFileProvider(staticRoot),
|
||||||
|
RequestPath = ""
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseCors("CorsPolicy");
|
app.UseCors("CorsPolicy");
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.UseWebSockets();
|
app.UseWebSockets();
|
||||||
|
|
||||||
app.UseEndpoints(end =>
|
app.UseEndpoints(end =>
|
||||||
{
|
{
|
||||||
ControllerEndpointRouteBuilderExtensions.MapControllers(end);
|
ControllerEndpointRouteBuilderExtensions.MapControllers(end);
|
||||||
|
|
||||||
|
// 프론트 테스트 위한 부분
|
||||||
|
end.MapFallbackToFile("index.html");
|
||||||
|
|
||||||
end.MapHub<ChatHub>("/chatHub");
|
end.MapHub<ChatHub>("/chatHub");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,11 @@ namespace Back.Program.Common.Auth
|
||||||
///
|
///
|
||||||
public class APIHeaderMiddleware
|
public class APIHeaderMiddleware
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly string[] _headerNames;
|
private readonly string[] _headerNames;
|
||||||
// private readonly IHeaderConfig _headerConfig;
|
// private readonly IHeaderConfig _headerConfig;
|
||||||
|
|
||||||
public APIHeaderMiddleware(RequestDelegate next, string[] headerNames)//, IHeaderConfig headerConfig)
|
public APIHeaderMiddleware(RequestDelegate next, string[] headerNames) //, IHeaderConfig headerConfig)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_headerNames = headerNames;
|
_headerNames = headerNames;
|
||||||
|
@ -25,36 +24,46 @@ namespace Back.Program.Common.Auth
|
||||||
await _next(context);
|
await _next(context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scoped 사용해서 값 가져오는 곳임
|
|
||||||
var headerConfig = context.RequestServices.GetRequiredService<IHeaderConfig>();
|
|
||||||
|
|
||||||
bool valid = false;
|
|
||||||
|
|
||||||
foreach (var header in _headerNames)
|
// 정적 파일 요청은 미들웨어 건너뜀
|
||||||
|
var path = context.Request.Path.Value;
|
||||||
|
if (path != null && (path.StartsWith("/api")))
|
||||||
{
|
{
|
||||||
/// context.Request.Headers.TryGetValue(header, out var headerValue)
|
// Scoped 사용해서 값 가져오는 곳임
|
||||||
/// header 를 찾는데 header
|
var headerConfig = context.RequestServices.GetRequiredService<IHeaderConfig>();
|
||||||
if (context.Request.Headers.TryGetValue(header, out var headerValue) &&
|
|
||||||
!string.IsNullOrWhiteSpace(headerValue))
|
bool valid = false;
|
||||||
|
|
||||||
|
foreach (var header in _headerNames)
|
||||||
{
|
{
|
||||||
var keyName = await headerConfig.GetExpectedHeaderValueAsync(headerValue);
|
/// context.Request.Headers.TryGetValue(header, out var headerValue)
|
||||||
if (keyName != string.Empty)
|
/// header 를 찾는데 header
|
||||||
|
if (context.Request.Headers.TryGetValue(header, out var headerValue) &&
|
||||||
|
!string.IsNullOrWhiteSpace(headerValue))
|
||||||
{
|
{
|
||||||
valid = true;
|
var keyName = await headerConfig.GetExpectedHeaderValueAsync(headerValue);
|
||||||
break;
|
if (keyName != string.Empty)
|
||||||
|
{
|
||||||
|
valid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!valid)
|
||||||
|
{
|
||||||
|
context.Response.StatusCode = StatusCodes.Status401Unauthorized;
|
||||||
|
await context.Response.WriteAsync($"Invalid header value");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await _next(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid)
|
|
||||||
{
|
{
|
||||||
context.Response.StatusCode = StatusCodes.Status401Unauthorized;
|
await _next(context);
|
||||||
await context.Response.WriteAsync($"Invalid header value");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await _next(context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user