Files
mixtape/zero.Api/ApiApplicationResolverHandler.cs
T

36 lines
902 B
C#
Raw Normal View History

2021-12-13 13:40:04 +01:00
using Microsoft.AspNetCore.Http;
namespace zero.Api;
public class ApiApplicationResolverHandler : IBackofficeApplicationResolverHandler
{
2022-01-07 19:31:04 +01:00
readonly IZeroOptions options;
public ApiApplicationResolverHandler(IZeroOptions options)
{
this.options = options;
}
2021-12-13 13:40:04 +01:00
public bool TryResolve(HttpContext context, IEnumerable<Application> applications, ZeroUser user, out Application resolved)
{
2022-01-07 19:31:04 +01:00
string path = options.ZeroPath.EnsureStartsWith('/').TrimEnd('/');
if (!context.Request.Path.ToString().StartsWith(path))
{
resolved = null;
return false;
}
string appKey = context.Request.Path.Value.Substring(path.Length).TrimStart('/').Split('/').ElementAtOrDefault(1);
if (appKey.HasValue())
2021-12-13 13:40:04 +01:00
{
resolved = applications.FirstOrDefault(x => x.Alias == appKey);
return resolved != null;
}
resolved = null;
return false;
}
}