-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
732 additions
and
1,030 deletions.
There are no files selected for viewing
1,621 changes: 610 additions & 1,011 deletions
1,621
src/Articulate.Tests.Website/appsettings-schema.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Articulate/Controllers/ArticulateDynamicRouteAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Articulate.Controllers | ||
{ | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public sealed class ArticulateDynamicRouteAttribute : Attribute | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/Articulate/Routing/ArticulateDynamicRouteSelectorPolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#nullable enable | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Articulate.Controllers; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.AspNetCore.Routing.Matching; | ||
using Umbraco.Cms.Web.Common.Routing; | ||
|
||
namespace Articulate.Routing | ||
{ | ||
/// <summary> | ||
/// Used when their is ambiguous route candidates due to multiple dynamic routes being assigned. | ||
/// </summary> | ||
/// <remarks> | ||
/// Ambiguous dynamic routes can occur if Umbraco detects a 404 and assigns a route, but sometimes its not | ||
/// actually a 404 because the articulate router occurs after the Umbraco router which handles 404 eagerly. | ||
/// This causes 2x candidates to be resolved and the first (umbraco) is chosen. | ||
/// If we detect that Articulate actually performed the routing, then we use that candidate instead. | ||
/// TODO: Ideally - Umbraco would dynamically route the 404 in a much later state which could be done, | ||
/// by a dynamic router that has a much larger Order so it occurs later in the pipeline instead of eagerly. | ||
/// </remarks> | ||
internal class ArticulateDynamicRouteSelectorPolicy : MatcherPolicy, IEndpointSelectorPolicy | ||
{ | ||
public override int Order => 100; | ||
|
||
public bool AppliesToEndpoints(IReadOnlyList<Endpoint> endpoints) | ||
{ | ||
// Don't apply this filter to any endpoint group that is a controller route | ||
// i.e. only dynamic routes. | ||
foreach (Endpoint endpoint in endpoints) | ||
{ | ||
ControllerAttribute? controller = endpoint.Metadata.GetMetadata<ControllerAttribute>(); | ||
if (controller != null) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
// then ensure this is only applied if all endpoints are IDynamicEndpointMetadata | ||
return endpoints.All(x => x.Metadata.GetMetadata<IDynamicEndpointMetadata>() != null); | ||
} | ||
|
||
public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates) | ||
{ | ||
var umbracoRouteValues = httpContext.Features.Get<UmbracoRouteValues>(); | ||
|
||
// If the request has been dynamically routed by articulate to an | ||
// Articulate controller | ||
if (umbracoRouteValues != null | ||
&& umbracoRouteValues.ControllerActionDescriptor.EndpointMetadata.Any(x => x is ArticulateDynamicRouteAttribute)) | ||
{ | ||
for (var i = 0; i < candidates.Count; i++) | ||
{ | ||
// If the candidate is an Articulate dynamic controller, set valid | ||
if (candidates[i].Endpoint.Metadata.GetMetadata<ArticulateDynamicRouteAttribute>() is not null) | ||
{ | ||
candidates.SetValidity(i, true); | ||
} | ||
else | ||
{ | ||
// else it is invalid | ||
candidates.SetValidity(i, false); | ||
} | ||
} | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters