2019-11-19 05:10:07 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-12-24 15:30:48 +00:00
|
|
|
|
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;
|
2019-12-24 15:01:06 +00:00
|
|
|
|
using Nancy;
|
|
|
|
|
using Nancy.Bootstrapper;
|
2019-12-24 15:30:48 +00:00
|
|
|
|
using Nancy.Configuration;
|
|
|
|
|
using Nancy.Diagnostics;
|
2019-11-19 05:10:07 +00:00
|
|
|
|
using Nancy.Hosting.Self;
|
2019-12-24 15:01:06 +00:00
|
|
|
|
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;
|
2019-12-24 15:01:06 +00:00
|
|
|
|
_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-12-24 15:01:06 +00:00
|
|
|
|
|
|
|
|
|
|
2019-11-19 05:10:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Address { get; }
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
_server.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_server?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-24 15:01:06 +00:00
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-12-24 15:30:48 +00:00
|
|
|
|
|
|
|
|
|
public override void Configure(INancyEnvironment environment)
|
|
|
|
|
{
|
|
|
|
|
environment.Tracing(
|
|
|
|
|
enabled: true,
|
|
|
|
|
displayErrorTraces: true);
|
|
|
|
|
}
|
2019-12-24 15:01:06 +00:00
|
|
|
|
}
|
2019-11-19 05:10:07 +00:00
|
|
|
|
}
|