Open TimHess opened 5 years ago
Hello, Mappings Actuator should also return the urls of razor pages? I would be happy to tackle this if you guys accept PRs.
We'd love to have your contribution on this issue, please let us know if you need any assistance getting started
Of course! I'm currently looking at how to get a list of all the registered razor pages, apparently it's not as "easy" as controller actions.
This starting point
Led me to some rough (and incomplete) code:
private readonly IEnumerable<EndpointDataSource> _endpointDataSources;
....
public MappingsEndpointMiddleware(
...
IEnumerable<EndpointDataSource> endpointDataSources = null,
ILogger<MappingsEndpointMiddleware> logger = null)
: base(endpoint, mgmtOptions, logger: logger)
{
...
_endpointDataSources = endpointDataSources;
}
...
protected internal ApplicationMappings GetApplicationMappings(HttpContext context)
{
...
if (_endpointDataSources != null)
{
// https://stackoverflow.com/questions/28435734/how-to-get-a-list-of-all-routes-in-asp-net-core
var endpoints = _endpointDataSources.SelectMany(es => es.Endpoints).OfType<RouteEndpoint>();
var output = endpoints.Select(
e =>
{
var controller = e.Metadata
.OfType<ControllerActionDescriptor>()
.FirstOrDefault();
var action = controller != null
? $"{controller.ControllerName}.{controller.ActionName}"
: null;
var controllerMethod = controller != null
? $"{controller.ControllerTypeInfo.FullName}:{controller.MethodInfo.Name}"
: null;
return new
{
Method = e.Metadata.OfType<HttpMethodMetadata>().FirstOrDefault()?.HttpMethods?[0],
Route = $"/{e.RoutePattern.RawText.TrimStart('/')}",
Action = action,
ControllerMethod = controllerMethod
};
});
foreach (var r in output)
{
// desc.Add(r.Route, new () { new () { Key = r.Route, Value = null } });
}
}
var contextMappings = new ContextMappings(desc);
return new ApplicationMappings(contextMappings);
}
/mappings currently doesn't know about razor pages, but it would be nice if it did