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); // 정적 파일 서빙을 가장 먼저 설정 (다른 모든 미들웨어보다 우선) 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); // 캐시 방지 미들웨어 (정적 파일이 처리되지 않은 경우에만 적용) 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")) { 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"; } await next(); }); // 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 // } // ); } } }