0927639cff
This reverts commit 6a166e3f5a.
69 lines
1.8 KiB
C#
69 lines
1.8 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using zero.Core.Extensions;
|
|
using zero.Core.Options;
|
|
using zero.Web.Middlewares;
|
|
using zero.Web.Routing;
|
|
|
|
namespace zero.Web
|
|
{
|
|
public static class ZeroApplicationBuilderExtensions
|
|
{
|
|
public static IApplicationBuilder UseZero(this IApplicationBuilder app)
|
|
{
|
|
IZeroOptions options = app.ApplicationServices.GetService<IZeroOptions>();
|
|
|
|
string path = options.BackofficePath.EnsureStartsWith('/').TrimEnd('/');
|
|
|
|
app.UseMiddleware<ZeroContextMiddleware>();
|
|
|
|
app.UseStaticFiles();
|
|
|
|
// map backoffice
|
|
app.UseWhen(ctx => ctx.Request.Path.ToString().StartsWith(path), builder =>
|
|
{
|
|
builder.UseRouting();
|
|
|
|
builder.UseAuthentication();
|
|
builder.UseAuthorization();
|
|
|
|
//builder.UseMiddleware<ZeroMiddleware>(options);
|
|
|
|
builder.UseEndpoints(endpoints =>
|
|
{
|
|
// setup route
|
|
//endpoints.MapControllerRoute(
|
|
// name: "setup",
|
|
// pattern: path + "/setup",
|
|
// defaults: new
|
|
// {
|
|
// controller = "ZeroSetup",
|
|
// action = "Index"
|
|
// }
|
|
//);
|
|
|
|
//// routes for API
|
|
//endpoints.MapControllerRoute(
|
|
// name: "api",
|
|
// pattern: path + "/api/{controller}/{action}/{id?}"
|
|
//);
|
|
|
|
// fallbacks for SPA
|
|
endpoints.MapFallbackToController(path + "/{**path}", "Index", "ZeroBackoffice");
|
|
});
|
|
});
|
|
|
|
return app;
|
|
}
|
|
|
|
|
|
public static IApplicationBuilder UseZeroRoutes(this IApplicationBuilder app)
|
|
{
|
|
return app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapDynamicControllerRoute<ZeroRoutesTransformer>("{**url}");
|
|
});
|
|
}
|
|
}
|
|
}
|