using Nancy;
using Nancy.Bootstrapper;
using Nancy.TinyIoc;
namespace Learun.Application.WebApi
{
///
/// 版 本 Learun-ADMS V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创建人:数字化智慧校园-框架开发组
/// 日 期:2017.05.12
/// 描 述:Nancy启动重载(用于解决跨域问题)
///
public class Bootstraper : DefaultNancyBootstrapper
{
///
/// 自定义请求启动函数
///
///
///
///
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
//CORS Enable
pipelines.AfterRequest.AddItemToEndOfPipeline((ctx) =>
{
var originlist = ctx.Request.Headers["Origin"];
foreach (var origin in originlist)
{
ctx.Response.WithHeader("Access-Control-Allow-Origin", origin);
}
ctx.Response.WithHeader("Access-Control-Allow-Methods", "POST,GET")
.WithHeader("Access-Control-Allow-Credentials", "true")
.WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type");
});
}
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
Nancy.Json.JsonSettings.MaxJsonLength = int.MaxValue;
}
}
}