From 2d959126b7a582d8a8614f1b429b93a00403a732 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Wed, 3 Jan 2018 15:41:58 -0600 Subject: [PATCH] (GH-10) use WebActivator Start for routes --- .../App_Start/NuGetODataConfig.cs | 30 +++++++++++++++++++ .../SimpleChocolateyServer.csproj | 1 + 2 files changed, 31 insertions(+) create mode 100644 src/SimpleChocolateyServer/App_Start/NuGetODataConfig.cs diff --git a/src/SimpleChocolateyServer/App_Start/NuGetODataConfig.cs b/src/SimpleChocolateyServer/App_Start/NuGetODataConfig.cs new file mode 100644 index 0000000..3127612 --- /dev/null +++ b/src/SimpleChocolateyServer/App_Start/NuGetODataConfig.cs @@ -0,0 +1,30 @@ +using System.Net.Http; +using System.Web.Http; +using System.Web.Http.Routing; +using NuGet.Server; +using NuGet.Server.V2; + +[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(SimpleChocolateyServer.App_Start.NuGetODataConfig), "Start")] + +namespace SimpleChocolateyServer.App_Start +{ + public static class NuGetODataConfig + { + public static void Start() + { + ServiceResolver.SetServiceResolver(new DefaultServiceResolver()); + + var config = GlobalConfiguration.Configuration; + + NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, "ChocolateyDefault", "chocolatey", "PackagesOData"); + + config.Routes.MapHttpRoute( + name: "NuGetDefault_ClearCache", + routeTemplate: "chocolatey/clear-cache", + defaults: new { controller = "PackagesOData", action = "ClearCache" }, + constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) } + ); + + } + } +} diff --git a/src/SimpleChocolateyServer/SimpleChocolateyServer.csproj b/src/SimpleChocolateyServer/SimpleChocolateyServer.csproj index 494ef05..3ec7d3f 100644 --- a/src/SimpleChocolateyServer/SimpleChocolateyServer.csproj +++ b/src/SimpleChocolateyServer/SimpleChocolateyServer.csproj @@ -141,6 +141,7 @@ Properties\SolutionVersion.cs +