geekbot/Geekbot.net/WebApi/WebConfig.cs

39 lines
1.4 KiB
C#
Raw Normal View History

using System.Diagnostics;
2018-05-14 00:41:05 +02:00
using Discord.Commands;
using Geekbot.net.Lib.Logger;
2017-10-12 16:34:10 +02:00
using Nancy;
using Nancy.Bootstrapper;
using Nancy.TinyIoc;
namespace Geekbot.net.WebApi
{
public class WebConfig : DefaultNancyBootstrapper
{
2018-05-14 00:41:05 +02:00
private readonly GeekbotLogger _logger;
private readonly CommandService _commands;
public WebConfig(GeekbotLogger logger, CommandService commands)
{
2018-05-14 00:41:05 +02:00
_logger = logger;
_commands = commands;
}
2018-05-14 00:41:05 +02:00
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
// Register Dependencies
container.Register<IGeekbotLogger>(_logger);
container.Register<CommandService>(_commands);
// Enable CORS
pipelines.AfterRequest.AddItemToEndOfPipeline(ctx =>
{
2018-05-14 00:41:05 +02:00
_logger.Information(LogSource.Api, ctx.Request.Path.ToString());
ctx.Response.WithHeader("Access-Control-Allow-Origin", "*")
2017-10-12 16:34:10 +02:00
.WithHeader("Access-Control-Allow-Methods", "GET")
.WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type")
.WithHeader("Last-Modified", Process.GetCurrentProcess().StartTime.ToString());
});
}
}
}