diff --git a/src/Umbraco.Cms.Api.Common/Security/Paths.cs b/src/Umbraco.Cms.Api.Common/Security/Paths.cs index 561a5d84bb58..61e89ed3a30d 100644 --- a/src/Umbraco.Cms.Api.Common/Security/Paths.cs +++ b/src/Umbraco.Cms.Api.Common/Security/Paths.cs @@ -1,3 +1,5 @@ +using Umbraco.Cms.Core; + namespace Umbraco.Cms.Api.Common.Security; public static class Paths @@ -14,7 +16,7 @@ public static class BackOfficeApi public static readonly string RevokeEndpoint = EndpointPath($"{EndpointTemplate}/revoke"); - private static string EndpointPath(string relativePath) => $"/umbraco/management/api/v1/{relativePath}"; + private static string EndpointPath(string relativePath) => $"/umbraco{Constants.Web.ManagementApiPath}v1/{relativePath}"; } public static class MemberApi diff --git a/src/Umbraco.Cms.Api.Management/DependencyInjection/ApplicationBuilderExtensions.cs b/src/Umbraco.Cms.Api.Management/DependencyInjection/ApplicationBuilderExtensions.cs index e7ce795dd51f..9018b97bee89 100644 --- a/src/Umbraco.Cms.Api.Management/DependencyInjection/ApplicationBuilderExtensions.cs +++ b/src/Umbraco.Cms.Api.Management/DependencyInjection/ApplicationBuilderExtensions.cs @@ -27,8 +27,7 @@ internal static IApplicationBuilder UseProblemDetailsExceptionHandling(this IApp var officePath = settings.GetBackOfficePath(hostingEnvironment); // Only use the API exception handler when we are requesting an API - // FIXME: magic string "management/api" is used several times across the codebase - return httpContext.Request.Path.Value?.StartsWith($"{officePath}/management/api/") ?? false; + return httpContext.Request.Path.Value?.StartsWith($"{officePath}{Constants.Web.ManagementApiPath}") ?? false; }, innerBuilder => { @@ -65,8 +64,7 @@ internal static IApplicationBuilder UseEndpoints(this IApplicationBuilder applic endpoints.MapControllers(); // Serve contract - // FIXME: magic string "management/api" is used several times across the codebase - endpoints.MapGet($"{officePath}/management/api/openapi.json", async context => + endpoints.MapGet($"{officePath}{Constants.Web.ManagementApiPath}openapi.json", async context => { await context.Response.SendFileAsync(new EmbeddedFileProvider(typeof(ManagementApiComposer).Assembly).GetFileInfo("OpenApi.json")); }); diff --git a/src/Umbraco.Cms.Api.Management/Routing/VersionedApiBackOfficeRouteAttribute.cs b/src/Umbraco.Cms.Api.Management/Routing/VersionedApiBackOfficeRouteAttribute.cs index 5c115eb5ccaa..e11aeb14b36d 100644 --- a/src/Umbraco.Cms.Api.Management/Routing/VersionedApiBackOfficeRouteAttribute.cs +++ b/src/Umbraco.Cms.Api.Management/Routing/VersionedApiBackOfficeRouteAttribute.cs @@ -1,5 +1,4 @@ - - +using Umbraco.Cms.Core; using Umbraco.Cms.Web.Common.Routing; namespace Umbraco.Cms.Api.Management.Routing; @@ -7,7 +6,7 @@ namespace Umbraco.Cms.Api.Management.Routing; public class VersionedApiBackOfficeRouteAttribute : BackOfficeRouteAttribute { public VersionedApiBackOfficeRouteAttribute(string template) - : base($"management/api/v{{version:apiVersion}}/{template.TrimStart('/')}") + : base($"{Constants.Web.ManagementApiPath}v{{version:apiVersion}}/{template.TrimStart('/')}") { } } diff --git a/src/Umbraco.Core/Constants-Web.cs b/src/Umbraco.Core/Constants-Web.cs index b7398778a577..36749cbb2b78 100644 --- a/src/Umbraco.Core/Constants-Web.cs +++ b/src/Umbraco.Core/Constants-Web.cs @@ -62,6 +62,11 @@ public const string public const string BackOfficeLoginArea = "UmbracoLogin"; // Used for area routes of non-api controllers for login } + /// + /// The "base" path to the Management API + /// + public const string ManagementApiPath = "/management/api/"; + public static class Routing { public const string ControllerToken = "controller"; diff --git a/src/Umbraco.Core/Routing/UmbracoRequestPaths.cs b/src/Umbraco.Core/Routing/UmbracoRequestPaths.cs index c1137e7052d1..82416c4f4176 100644 --- a/src/Umbraco.Core/Routing/UmbracoRequestPaths.cs +++ b/src/Umbraco.Core/Routing/UmbracoRequestPaths.cs @@ -40,7 +40,7 @@ public UmbracoRequestPaths(IOptions globalSettings, IHostingEnvi _previewMvcPath = "/" + mvcArea + "/Preview/"; _surfaceMvcPath = "/" + mvcArea + "/Surface/"; _apiMvcPath = "/" + mvcArea + "/Api/"; - _managementApiPath = "/" + mvcArea + "/management/api/"; + _managementApiPath = "/" + mvcArea + Constants.Web.ManagementApiPath; _installPath = hostingEnvironment.ToAbsolute(Constants.SystemDirectories.Install); _umbracoRequestPathsOptions = umbracoRequestPathsOptions; }