2021-12-12 15:41:51 +01:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2021-11-29 18:25:50 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-12-12 15:41:51 +01:00
|
|
|
using Microsoft.AspNetCore.Routing;
|
2021-11-29 18:25:50 +01:00
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
|
|
|
|
|
namespace zero.Api;
|
|
|
|
|
|
|
|
|
|
public class ZeroApiPlugin : ZeroPlugin
|
|
|
|
|
{
|
|
|
|
|
internal Action<IServiceCollection, IConfiguration> PostConfigureServices = null;
|
|
|
|
|
|
|
|
|
|
public ZeroApiPlugin()
|
|
|
|
|
{
|
|
|
|
|
Options.Name = "zero.Api";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
services.AddOptions<ApiOptions>().Bind(configuration.GetSection("Zero:Api")).Configure<IWebHostEnvironment>(ConfigureOptions);
|
2021-11-30 15:35:50 +01:00
|
|
|
services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, ZeroApiMvcOptions>());
|
2021-12-13 13:40:04 +01:00
|
|
|
services.AddTransient<IBackofficeApplicationResolverHandler, ApiApplicationResolverHandler>();
|
2021-12-14 01:23:03 +01:00
|
|
|
services.AddTransient<ApiUnhandledExceptionMiddleware>();
|
2021-11-29 18:25:50 +01:00
|
|
|
|
2021-12-30 11:11:34 +01:00
|
|
|
services.ConfigureOptions<ConfigureApiJsonOptions>();
|
|
|
|
|
|
2021-12-12 15:41:51 +01:00
|
|
|
ZeroModuleCollection modules = new();
|
2021-11-29 18:25:50 +01:00
|
|
|
|
2021-12-12 15:41:51 +01:00
|
|
|
modules.Add<Endpoints.Applications.ApplicationModule>();
|
|
|
|
|
modules.Add<Endpoints.Countries.CountryModule>();
|
|
|
|
|
modules.Add<Endpoints.Languages.LanguageModule>();
|
|
|
|
|
modules.Add<Endpoints.Search.SearchModule>();
|
|
|
|
|
modules.Add<Endpoints.Translations.TranslationModule>();
|
|
|
|
|
modules.Add<Endpoints.Mails.MailModule>();
|
|
|
|
|
modules.Add<Endpoints.Pages.PageModule>();
|
|
|
|
|
modules.Add<Endpoints.Media.MediaModule>();
|
|
|
|
|
modules.Add<Endpoints.Spaces.SpaceModule>();
|
2021-12-22 00:14:48 +01:00
|
|
|
modules.Add<Endpoints.Integrations.IntegrationModule>();
|
2021-12-26 01:42:21 +01:00
|
|
|
modules.Add<Endpoints.Users.UserModule>();
|
2022-01-12 18:49:36 +01:00
|
|
|
modules.Add<Endpoints.PageModules.PageModuleModule>();
|
2021-11-29 18:25:50 +01:00
|
|
|
|
2021-12-12 15:41:51 +01:00
|
|
|
modules.ConfigureServices(services, configuration);
|
|
|
|
|
|
2021-11-29 18:25:50 +01:00
|
|
|
PostConfigureServices?.Invoke(services, configuration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-12-12 15:41:51 +01:00
|
|
|
public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
string path = "/zero/api";
|
|
|
|
|
|
|
|
|
|
app.UseWhen(ctx => ctx.Request.Path.StartsWithSegments(path), appScoped =>
|
|
|
|
|
{
|
|
|
|
|
appScoped.UseEndpoints(endpoints =>
|
|
|
|
|
{
|
|
|
|
|
//IZeroOptions options = app.ApplicationServices.GetService<IZeroOptions>(); // TODO oO
|
|
|
|
|
// see https://our.umbraco.com/documentation/reference/routing/custom-routes#where-to-put-your-routing-logic
|
|
|
|
|
//string path = options.BackofficePath.EnsureStartsWith('/').TrimEnd('/');
|
|
|
|
|
//endpoints.MapFallbackToController(path + "/{**path}", "Index", "ZeroIndex");
|
|
|
|
|
|
|
|
|
|
//endpoints.MapControllers();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-11-29 18:25:50 +01:00
|
|
|
protected void ConfigureOptions(ApiOptions options, IWebHostEnvironment env)
|
|
|
|
|
{
|
|
|
|
|
options.Search.Enabled = true;
|
|
|
|
|
//Map<Page>().Display((x, res, opts) =>
|
|
|
|
|
//{
|
|
|
|
|
// PageType pageType = opts.Pages.GetByAlias(x.PageTypeAlias);
|
|
|
|
|
// if (pageType != null)
|
|
|
|
|
// {
|
|
|
|
|
// res.Icon = pageType.Icon;
|
|
|
|
|
// }
|
|
|
|
|
// res.Url = "/pages/edit/" + x.Id;
|
|
|
|
|
//});
|
|
|
|
|
//Map<MediaFolder>("fth-image");
|
|
|
|
|
}
|
|
|
|
|
}
|