Merge pull request #309 from wabbajack-tools/cors-in-caching

Cors in caching
This commit is contained in:
Timothy Baldridge 2019-12-24 09:48:13 -08:00 committed by GitHub
commit 1d13a330d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 186 deletions

View File

@ -1,39 +0,0 @@
namespace Wabbajack.CacheServer.Test
{
//[TestClass]
public class CacheServerTests
{
// The server works, we just need to figure out proper testing.
/*
private Server _server;
private HttpClient _client;
public TestContext TestContext { get; set; }
[TestInitialize]
public void Setup()
{
Utils.LogMessages.Subscribe(msg => TestContext.WriteLine(msg));
_server = new Server("http://localhost:42420");
_server.Start();
_client = new NexusApiClient().HttpClient;
_client.BaseAddress = new Uri(_server.Address);
}
[TestCleanup]
public void Cleanup()
{
_server.Dispose();
}
[TestMethod]
public void TestAPIs()
{
_client.GetStringSync("/v1/games/skyrim/mods/70260.json");
_client.GetStringSync("/v1/games/fallout4/mods/38590/files/156741.json");
_client.GetStringSync(
"/nexus_cache_dir/68747470733a2f2f6170692e6e657875736d6f64732e636f6d2f76312f67616d65732f6f626c6976696f6e2f6d6f64732f383530302f66696c65732f363939332e6a736f6e.json");
}*/
}
}

View File

@ -1,19 +0,0 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Wabbajack.CacheServer.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Wabbajack.CacheServer.Test")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("f101853e-6b12-4f7b-92a6-849fdb90aa3d")]
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -1,104 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F101853E-6B12-4F7B-92A6-849FDB90AA3D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Wabbajack.CacheServer.Test</RootNamespace>
<AssemblyName>Wabbajack.CacheServer.Test</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>CS1998</NoWarn>
<WarningsAsErrors>CS4014</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>CS1998</NoWarn>
<WarningsAsErrors>CS4014</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="CacheServerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Wabbajack.CacheServer\Wabbajack.CacheServer.csproj">
<Project>{bdc9a094-d235-47cd-83ca-44199b60ab20}</Project>
<Name>Wabbajack.CacheServer</Name>
</ProjectReference>
<ProjectReference Include="..\Wabbajack.Common\Wabbajack.Common.csproj">
<Project>{B3F3FB6E-B9EB-4F49-9875-D78578BC7AE5}</Project>
<Name>Wabbajack.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Wabbajack.Lib\Wabbajack.Lib.csproj">
<Project>{0a820830-a298-497d-85e0-e9a89efef5fe}</Project>
<Name>Wabbajack.Lib</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="MSTest.TestAdapter">
<Version>2.0.0</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>2.0.0</Version>
</PackageReference>
<PackageReference Include="System.Reactive">
<Version>4.3.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View 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}";
}
}
}

View File

@ -26,6 +26,7 @@ namespace Wabbajack.CacheServer
public List<(Archive archive, bool)> Archives { get; set; }
public DownloadMetadata DownloadMetaData { get; set; }
public bool HasFailures { get; set; }
public string MachineName { get; set; }
}
public static Dictionary<string, ModListStatus> ModLists { get; set; }
@ -190,7 +191,7 @@ namespace Wabbajack.CacheServer
var status = new ModListStatus
{
Name = list.Title,
Name = list.Title,
Archives = validated.OrderBy(v => v.archive.Name).ToList(),
DownloadMetaData = list.DownloadMetadata,
HasFailures = validated.Any(v => v.is_failed)

View File

@ -1,11 +1,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
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;
using Nancy.Hosting.Self;
using Nancy.TinyIoc;
namespace Wabbajack.CacheServer
{
@ -17,11 +23,11 @@ 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 +42,24 @@ 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");
});
}
public override void Configure(INancyEnvironment environment)
{
environment.Tracing(
enabled: true,
displayErrorTraces: true);
}
}
}

View File

@ -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>

View File

@ -34,8 +34,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.VirtualFileSystem
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.CacheServer", "Wabbajack.CacheServer\Wabbajack.CacheServer.csproj", "{BDC9A094-D235-47CD-83CA-44199B60AB20}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.CacheServer.Test", "Wabbajack.CacheServer.Test\Wabbajack.CacheServer.Test.csproj", "{F101853E-6B12-4F7B-92A6-849FDB90AA3D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug (no commandargs)|Any CPU = Debug (no commandargs)|Any CPU
@ -229,24 +227,6 @@ Global
{BDC9A094-D235-47CD-83CA-44199B60AB20}.Release|x64.Build.0 = Release|Any CPU
{BDC9A094-D235-47CD-83CA-44199B60AB20}.Release|x86.ActiveCfg = Release|Any CPU
{BDC9A094-D235-47CD-83CA-44199B60AB20}.Release|x86.Build.0 = Release|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Debug (no commandargs)|Any CPU.ActiveCfg = Debug|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Debug (no commandargs)|Any CPU.Build.0 = Debug|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Debug (no commandargs)|x64.ActiveCfg = Debug|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Debug (no commandargs)|x64.Build.0 = Debug|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Debug (no commandargs)|x86.ActiveCfg = Debug|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Debug (no commandargs)|x86.Build.0 = Debug|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Debug|x64.ActiveCfg = Debug|x64
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Debug|x64.Build.0 = Debug|x64
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Debug|x86.ActiveCfg = Debug|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Debug|x86.Build.0 = Debug|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Release|Any CPU.Build.0 = Release|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Release|x64.ActiveCfg = Release|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Release|x64.Build.0 = Release|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Release|x86.ActiveCfg = Release|Any CPU
{F101853E-6B12-4F7B-92A6-849FDB90AA3D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE