47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using Nancy;
|
|
using Nancy.Bootstrapper;
|
|
using Nancy.Conventions;
|
|
using Nancy.Swagger.Annotations;
|
|
using Nancy.Swagger.Services;
|
|
using Nancy.TinyIoc;
|
|
using Swagger.ObjectModel;
|
|
|
|
namespace 电子展板.WebModule
|
|
{
|
|
public class ApplicationBootstrapper : DefaultNancyBootstrapper
|
|
{
|
|
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
|
|
{
|
|
SwaggerMetadataProvider.SetInfo("API", "v1.0", "电子展板", new Contact
|
|
{
|
|
EmailAddress = "18862253202@qq.com",
|
|
Name = "大师兄法号随缘",
|
|
Url = "https://www.cnblogs.com/zjwno1"
|
|
}, "http://www.cnblogs.com/zjwno1");
|
|
base.ApplicationStartup(container, pipelines);
|
|
//仅显示有特性的接口
|
|
SwaggerAnnotationsConfig.ShowOnlyAnnotatedRoutes = true;
|
|
}
|
|
|
|
protected override void ConfigureConventions(NancyConventions nancyConventions)
|
|
{
|
|
base.ConfigureConventions(nancyConventions);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 允许跨域
|
|
/// </summary>
|
|
/// <param name="container"></param>
|
|
/// <param name="pipelines"></param>
|
|
/// <param name="context"></param>
|
|
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
|
|
{
|
|
pipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Origin", "*"));
|
|
pipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Headers", "*"));
|
|
pipelines.AfterRequest.AddItemToEndOfPipeline(x => x.Response.Headers.Add("Access-Control-Allow-Methods", "*"));
|
|
}
|
|
}
|
|
|
|
}
|