Skip to content
Browse files

Added a FeedOnlyMode configuration to allow service feeds only

  • Loading branch information...
1 parent 336d471 commit 7d35cc0d8d12f0a5da0681f995877fcc9970afb9 @deepakaravindr deepakaravindr committed Jun 10, 2014
View
10 src/NuGetGallery/App_Start/AppActivator.cs
@@ -67,7 +67,7 @@ public static void PostStart()
// Get configuration from the kernel
var config = Container.Kernel.Get<IAppConfiguration>();
BackgroundJobsPostStart(config);
- AppPostStart();
+ AppPostStart(config);
BundlingPostStart();
}
@@ -168,9 +168,13 @@ private static void ElmahPreStart()
ServiceCenter.Current = _ => Container.Kernel;
}
- private static void AppPostStart()
+ private static void AppPostStart(IAppConfiguration configuration)
{
- Routes.RegisterRoutes(RouteTable.Routes);
+ if (!configuration.FeedOnlyMode)
+ {
+ Routes.RegisterRoutes(RouteTable.Routes);
+ }
+ Routes.RegisterApiV2Routes(RouteTable.Routes);
Routes.RegisterServiceRoutes(RouteTable.Routes);
AreaRegistration.RegisterAllAreas();
View
135 src/NuGetGallery/App_Start/Routes.cs
@@ -276,15 +276,65 @@ public static void RegisterRoutes(RouteCollection routes)
"v1/PublishedPackages/Publish",
new { controller = "Api", action = "PublishPackage" });
+ // Redirected Legacy Routes
+
+ routes.Redirect(
+ r => r.MapRoute(
+ "ReportAbuse",
+ "Package/ReportAbuse/{id}/{version}",
+ new { controller = "Packages", action = "ReportAbuse" }),
+ permanent: true).To(packageVersionActionRoute);
+
+ routes.Redirect(
+ r => r.MapRoute(
+ "PackageActions",
+ "Package/{action}/{id}",
+ new { controller = "Packages", action = "ContactOwners" },
+ // This next bit looks bad, but it's not. It will never change because
+ // it's mapping the legacy routes to the new better routes.
+ new { action = "ContactOwners|ManagePackageOwners" }),
+ permanent: true).To(packageActionRoute);
+
+ routes.Redirect(
+ r => r.MapRoute(
+ RouteName.ListPackages,
+ "List/Packages",
+ new { controller = "Packages", action = "ListPackages" }),
+ permanent: true).To(packageListRoute);
+
+ routes.Redirect(
+ r => r.MapRoute(
+ RouteName.DisplayPackage,
+ "List/Packages/{id}/{version}",
+ new { controller = "Packages", action = "DisplayPackage", version = UrlParameter.Optional }),
+ permanent: true).To(packageDisplayRoute);
+
+ routes.Redirect(
+ r => r.MapRoute(
+ RouteName.NewSubmission,
+ "Contribute/NewSubmission",
+ new { controller = "Packages", action = "UploadPackage" }),
+ permanent: true).To(uploadPackageRoute);
+
+ routes.Redirect(
+ r => r.MapRoute(
+ "LegacyDownloadRoute",
+ "v1/Package/Download/{id}/{version}",
+ new { controller = "Api", action = "GetPackageApi", version = UrlParameter.Optional }),
+ permanent: true).To(downloadRoute);
+ }
+
+ public static void RegisterApiV2Routes(RouteCollection routes)
+ {
// V2 routes
routes.MapRoute(
"v2" + RouteName.VerifyPackageKey,
"api/v2/verifykey/{id}/{version}",
- new {
- controller = "Api",
+ new {
+ controller = "Api",
action = "VerifyPackageKey",
- id = UrlParameter.Optional,
- version = UrlParameter.Optional
+ id = UrlParameter.Optional,
+ version = UrlParameter.Optional
});
routes.MapRoute(
@@ -294,18 +344,6 @@ public static void RegisterRoutes(RouteCollection routes)
constraints: new { httpMethod = new HttpMethodConstraint("GET") });
routes.MapRoute(
- "v2" + RouteName.DeletePackageApi,
- "api/v2/package/{id}/{version}",
- new { controller = "Api", action = "DeletePackageApi" },
- constraints: new { httpMethod = new HttpMethodConstraint("DELETE") });
-
- routes.MapRoute(
- "v2" + RouteName.PublishPackageApi,
- "api/v2/package/{id}/{version}",
- new { controller = "Api", action = "PublishPackageApi" },
- constraints: new { httpMethod = new HttpMethodConstraint("POST") });
-
- routes.MapRoute(
"v2" + RouteName.DownloadPackage,
"api/v2/package/{id}/{version}",
defaults: new { controller = "Api", action = "GetPackageApi", version = UrlParameter.Optional },
@@ -318,6 +356,18 @@ public static void RegisterRoutes(RouteCollection routes)
constraints: new { httpMethod = new HttpMethodConstraint("PUT") });
routes.MapRoute(
+ "v2" + RouteName.DeletePackageApi,
+ "api/v2/package/{id}/{version}",
+ new { controller = "Api", action = "DeletePackage" },
+ constraints: new { httpMethod = new HttpMethodConstraint("DELETE") });
+
+ routes.MapRoute(
+ "v2" + RouteName.PublishPackageApi,
+ "api/v2/package/{id}/{version}",
+ new { controller = "Api", action = "PublishPackage" },
+ constraints: new { httpMethod = new HttpMethodConstraint("POST") });
+
+ routes.MapRoute(
"v2PackageIds",
"api/v2/package-ids",
new { controller = "Api", action = "PackageIDs" });
@@ -340,12 +390,6 @@ public static void RegisterRoutes(RouteCollection routes)
constraints: new { httpMethod = new HttpMethodConstraint("GET") });
routes.MapRoute(
- RouteName.Team,
- "api/v2/team",
- defaults: new { controller = "Api", action = "Team" },
- constraints: new { httpMethod = new HttpMethodConstraint("GET") });
-
- routes.MapRoute(
RouteName.Status,
"api/status",
new { controller = "Api", action = "StatusApi" });
@@ -354,53 +398,6 @@ public static void RegisterRoutes(RouteCollection routes)
RouteName.DownloadNuGetExe,
"nuget.exe",
new { controller = "Api", action = "GetNuGetExeApi" });
-
- // Redirected Legacy Routes
-
- routes.Redirect(
- r => r.MapRoute(
- "ReportAbuse",
- "Package/ReportAbuse/{id}/{version}",
- new { controller = "Packages", action = "ReportAbuse" }),
- permanent: true).To(packageVersionActionRoute);
-
- routes.Redirect(
- r => r.MapRoute(
- "PackageActions",
- "Package/{action}/{id}",
- new { controller = "Packages", action = "ContactOwners" },
- // This next bit looks bad, but it's not. It will never change because
- // it's mapping the legacy routes to the new better routes.
- new { action = "ContactOwners|ManagePackageOwners" }),
- permanent: true).To(packageActionRoute);
-
- routes.Redirect(
- r => r.MapRoute(
- RouteName.ListPackages,
- "List/Packages",
- new { controller = "Packages", action = "ListPackages" }),
- permanent: true).To(packageListRoute);
-
- routes.Redirect(
- r => r.MapRoute(
- RouteName.DisplayPackage,
- "List/Packages/{id}/{version}",
- new { controller = "Packages", action = "DisplayPackage", version = UrlParameter.Optional }),
- permanent: true).To(packageDisplayRoute);
-
- routes.Redirect(
- r => r.MapRoute(
- RouteName.NewSubmission,
- "Contribute/NewSubmission",
- new { controller = "Packages", action = "UploadPackage" }),
- permanent: true).To(uploadPackageRoute);
-
- routes.Redirect(
- r => r.MapRoute(
- "LegacyDownloadRoute",
- "v1/Package/Download/{id}/{version}",
- new { controller = "Api", action = "GetPackageApi", version = UrlParameter.Optional }),
- permanent: true).To(downloadRoute);
}
// note: Pulled out service route registration separately because it's not testable T.T (won't run outside IIS/WAS)
View
5 src/NuGetGallery/Configuration/AppConfiguration.cs
@@ -52,6 +52,11 @@ public class AppConfiguration : IAppConfiguration
public bool ReadOnlyMode { get; set; }
/// <summary>
+ /// Gets if only service feeds should be registered
+ /// </summary>
+ public bool FeedOnlyMode { get; set; }
+
+ /// <summary>
/// Gets the local directory in which to store files.
/// </summary>
[DefaultValue("~/App_Data/Files")]
View
5 src/NuGetGallery/Configuration/IAppConfiguration.cs
@@ -51,6 +51,11 @@ public interface IAppConfiguration
bool ReadOnlyMode { get; set; }
/// <summary>
+ /// Gets if only service feeds should be registered
+ /// </summary>
+ bool FeedOnlyMode { get; set; }
+
+ /// <summary>
/// Gets the local directory in which to store files.
/// </summary>
string FileStorageDirectory { get; set; }

0 comments on commit 7d35cc0

Please sign in to comment.
Something went wrong with that request. Please try again.