using Microsoft.Owin;
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;

namespace Project.OWIN
{
    public class Startup
    {
        public void Configuration(IAppBuilder appBuilder)
        {
            // Configure Web API for Self-Host
            HttpConfiguration config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();

            //메인파일 처리 방법
            IHttpRoute defaultRoute =
                config.Routes.CreateRoute("{controller}/{action}/{id}",
                new { controller = "home", action = "index", id = RouteParameter.Optional },
                null);

            //기타파일들 처리 방법
            IHttpRoute cssRoute =
              config.Routes.CreateRoute("{path}/{subdir}/{resource}.{ext}",
              new { controller = "resource", action = "file", id = RouteParameter.Optional },
              null);

            IHttpRoute mifRoute =
               config.Routes.CreateRoute("{path}/{resource}.{ext}",
               new { controller = "resource", action = "file", id = RouteParameter.Optional },
               null);

            IHttpRoute icoRoute =
              config.Routes.CreateRoute("{resource}.{ext}",
              new { controller = "resource", action = "file", id = RouteParameter.Optional },
              null);

            config.Routes.Add("mifRoute", mifRoute);
            config.Routes.Add("icoRoute", icoRoute);
            config.Routes.Add("cssRoute", cssRoute);
            config.Routes.Add("defaultRoute", defaultRoute);

            appBuilder.UseStaticFiles();
            appBuilder.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            appBuilder.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
            //    }
            // );



        }

    }
}
