mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Add CORS support to caching server, add heartbeat endpoint
This commit is contained in:
parent
271fe56f6b
commit
32b1a27e34
24
Wabbajack.CacheServer/Heartbeat.cs
Normal file
24
Wabbajack.CacheServer/Heartbeat.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Nancy;
|
||||
|
||||
namespace Wabbajack.CacheServer
|
||||
{
|
||||
public class Heartbeat : NancyModule
|
||||
{
|
||||
private static DateTime startTime = DateTime.Now;
|
||||
|
||||
public Heartbeat() : base("/")
|
||||
{
|
||||
Get("/heartbeat", HandleHeartbeat);
|
||||
}
|
||||
|
||||
private object HandleHeartbeat(object arg)
|
||||
{
|
||||
return $"Service is live for: {DateTime.Now - startTime}";
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ namespace Wabbajack.CacheServer
|
||||
Utils.LogMessages.Subscribe(Console.WriteLine);
|
||||
using (var server = new Server("http://localhost:8080"))
|
||||
{
|
||||
ListValidationService.Start();
|
||||
//ListValidationService.Start();
|
||||
server.Start();
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
@ -5,7 +5,10 @@ using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Nancy;
|
||||
using Nancy.Bootstrapper;
|
||||
using Nancy.Hosting.Self;
|
||||
using Nancy.TinyIoc;
|
||||
|
||||
namespace Wabbajack.CacheServer
|
||||
{
|
||||
@ -17,11 +20,12 @@ namespace Wabbajack.CacheServer
|
||||
public Server(string address)
|
||||
{
|
||||
Address = address;
|
||||
_config = new HostConfiguration();
|
||||
_config.MaximumConnectionCount = 24;
|
||||
_config = new HostConfiguration {MaximumConnectionCount = 24, RewriteLocalhost = true};
|
||||
|
||||
//_config.UrlReservations.CreateAutomatically = true;
|
||||
_config.RewriteLocalhost = true;
|
||||
_server = new NancyHost(_config, new Uri(address));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public string Address { get; }
|
||||
@ -36,4 +40,17 @@ namespace Wabbajack.CacheServer
|
||||
_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");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,7 @@
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Server.cs" />
|
||||
<Compile Include="Heartbeat.cs" />
|
||||
<Compile Include="TestingEndpoints.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user