Browse Source

Fix path base.

pull/1302/head
Sebastian Stehle 3 months ago
parent
commit
68fc8fabab
  1. 47
      backend/src/Squidex.Web/PathBaseMiddlewareExtensions.cs
  2. 1
      backend/src/Squidex.Web/Resources.cs
  3. 2
      backend/src/Squidex/Startup.cs

47
backend/src/Squidex.Web/PathBaseMiddlewareExtensions.cs

@ -0,0 +1,47 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Squidex.Hosting;
namespace Squidex.Web;
public static class PathBaseMiddlewareExtensions
{
public static IApplicationBuilder UseFallbackPathBase(this IApplicationBuilder app)
{
var urlGenerator = app.ApplicationServices.GetRequiredService<IUrlGenerator>();
var configuredBase = urlGenerator.BuildBasePath();
if (string.IsNullOrWhiteSpace(configuredBase))
{
return app;
}
var pathBase = new PathString(configuredBase);
return app.Use(async (context, next) =>
{
if (context.Request.PathBase.HasValue)
{
await next();
return;
}
context.Request.PathBase = pathBase;
if (context.Request.Path.StartsWithSegments(pathBase, StringComparison.Ordinal, out var remainder))
{
context.Request.Path = remainder;
}
await next();
});
}
}

1
backend/src/Squidex.Web/Resources.cs

@ -170,7 +170,6 @@ public sealed class Resources(ApiController controller)
var url = Controller.Url(action, values);
var basePath = Controller.HttpContext.Request.PathBase;
if (url.StartsWith(Controller.HttpContext.Request.PathBase, StringComparison.OrdinalIgnoreCase))
{
url = url[basePath.Value!.Length..];

2
backend/src/Squidex/Startup.cs

@ -73,7 +73,7 @@ public sealed class Startup(IConfiguration config)
{
app.UseWebSockets();
app.UseCookiePolicy();
app.UseDefaultPathBase();
app.UseFallbackPathBase();
app.UseDefaultForwardRules();
app.UseSquidexLogging();
app.UseSquidexLocalization();

Loading…
Cancel
Save