wabbajack/Wabbajack.CacheServer/Server.cs

66 lines
1.7 KiB
C#
Raw Normal View History

2019-11-19 05:10:07 +00:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
2019-11-19 05:10:07 +00:00
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using Nancy;
using Nancy.Bootstrapper;
using Nancy.Configuration;
using Nancy.Diagnostics;
2019-11-19 05:10:07 +00:00
using Nancy.Hosting.Self;
using Nancy.TinyIoc;
2019-11-19 05:10:07 +00:00
namespace Wabbajack.CacheServer
{
public class Server : IDisposable
{
private NancyHost _server;
private HostConfiguration _config;
public Server(string address)
{
Address = address;
_config = new HostConfiguration {MaximumConnectionCount = 24, RewriteLocalhost = true};
2019-11-19 05:10:07 +00:00
//_config.UrlReservations.CreateAutomatically = true;
_server = new NancyHost(_config, new Uri(address));
2019-11-19 05:10:07 +00:00
}
public string Address { get; }
public void Start()
{
_server.Start();
}
public void Dispose()
{
_server?.Dispose();
}
}
public class CachingBootstrapper : DefaultNancyBootstrapper
{
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
pipelines.AfterRequest.AddItemToEndOfPipeline(ctx =>
{
ctx.Response.WithHeader("Access-Control-Allow-Origin", "*")
.WithHeader("Access-Control-Allow-Methods", "POST, GET")
.WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type");
});
}
public override void Configure(INancyEnvironment environment)
{
environment.Tracing(
enabled: true,
displayErrorTraces: true);
}
}
2019-11-19 05:10:07 +00:00
}