Created
May 17, 2013 17:21
-
-
Save puryfury/5600568 to your computer and use it in GitHub Desktop.
Nancy Manage static contents with hooking builder that add a header when request static content.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Configuration; | |
| using System.Linq; | |
| using System.Reflection; | |
| using CustomerWanso.Defined; | |
| using Nancy; | |
| using Nancy.Conventions; | |
| using Nancy.Extensions; | |
| using Nancy.Bootstrappers.Ninject; | |
| using Nancy.ViewEngines; | |
| using Nancy.ErrorHandling; | |
| namespace CustomerWanso | |
| { | |
| public class Startup : NinjectNancyBootstrapper | |
| { | |
| protected override void ConfigureConventions(Nancy.Conventions.NancyConventions nancyConventions) | |
| { | |
| base.ConfigureConventions(nancyConventions); | |
| //정적 파일(이미지, 스타일, 자바스크립트 등) 폴더 모음 | |
| string[] paths = { "/Styles", "/Scripts", "/Images" }; | |
| //응답 객체를 후크를 사용하여 경우에 따른 도메인 허용 헤더 삽입 | |
| Func<NancyContext, Response, Response> hook = (ctx,res) => | |
| { | |
| if (res != null) res.WithHeader("Access-Control-Allow-Origin", "*"); | |
| return res; | |
| }; | |
| //각 정적 파일별로 정적 폴더 대상 선언 | |
| foreach (string path in paths) | |
| { | |
| var method = StaticContentConventionBuilder.AddDirectory(path); | |
| nancyConventions.StaticContentsConventions.Add((a, b) => hook(a,method(a, b))); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment