Files
Groupware/Project/Web/Startup.cs
backuppc 709ca7c85a 개인정보 관련 업데이트 진행
ot 정보는 타인이 못봄
휴가신청 관련건도 타인이 못봄
2025-11-11 11:43:29 +09:00

112 lines
3.8 KiB
C#

using Microsoft.Owin;
using Microsoft.Owin.StaticFiles;
using Owin;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Routing;
using Project.Web.Controllers;
namespace Project.OWIN
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
// 캐시 방지 미들웨어를 가장 먼저 설정 (정적 파일 서빙보다 우선)
app.Use(async (context, next) =>
{
var path = context.Request.Path.Value;
// 모든 정적 리소스에 대해 캐시 방지 헤더 설정
if (path.EndsWith(".js") ||
path.EndsWith(".css") ||
path.EndsWith(".jsx") ||
path.EndsWith(".tsx") ||
path.EndsWith(".html") ||
path.EndsWith(".htm"))
{
context.Response.Headers["Cache-Control"] = "no-cache, no-store, must-revalidate";
context.Response.Headers["Pragma"] = "no-cache";
context.Response.Headers["Expires"] = "0";
}
// JSX/TSX 파일을 JavaScript로 처리
if (path.EndsWith(".jsx") || path.EndsWith(".tsx"))
{
context.Response.ContentType = "application/javascript; charset=utf-8";
}
await next();
});
// 정적 파일 서빙 설정
var staticFileOptions = new FileServerOptions
{
EnableDefaultFiles = true,
DefaultFilesOptions = { DefaultFileNames = { "index.html" } },
FileSystem = new Microsoft.Owin.FileSystems.PhysicalFileSystem("Web/wwwroot"),
RequestPath = Microsoft.Owin.PathString.Empty
};
app.UseFileServer(staticFileOptions);
// Configure Web API for Self-Host (정적 파일 후에 설정)
HttpConfiguration config = new HttpConfiguration();
//라우팅 설정
config.MapHttpAttributeRoutes();
// 컨트롤러만 있는 경우 기본 액션을 Index로 설정
config.Routes.MapHttpRoute(
name: "ControllerOnly",
routeTemplate: "{controller}",
defaults: new { action = "Index" }
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// JSON 포맷터 설정
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
// 파일 업로드 설정
config.Formatters.Remove(config.Formatters.XmlFormatter);
app.UseWebApi(config);
//appBuilder.UseFileServer(new FileServerOptions
//{
// RequestPath = new PathString(string.Empty),
// FileSystem = new PhysicalFileSystem("./MySubFolder"),
// EnableDirectoryBrowsing = true,
//});
//appBuilder.UseStageMarker(PipelineStage.MapHandler);
//config.Routes.MapHttpRoute(
// name: "ignore",
// routeTemplate: @".*\.(css|js|gif|jpg)(/.*)?",
// defaults: new
// {
// controller = "file",
// action = "readtext",
// id = RouteParameter.Optional
// }
// );
}
}
}