Browse Source

Cleanup

pull/1/head
Sebastian 9 years ago
parent
commit
7ab791e8ad
  1. 52
      src/Squidex/Pipeline/SingleUrlsMiddleware.cs
  2. 5
      src/Squidex/Startup.cs
  3. 5
      src/Squidex/appsettings.Production.json

52
src/Squidex/Pipeline/SingleUrlsMiddleware.cs

@ -1,52 +0,0 @@
// ==========================================================================
// SingleUrlsMiddleware.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace Squidex.Pipeline
{
public sealed class SingleUrlsMiddleware
{
private readonly RequestDelegate next;
private readonly ILogger<SingleUrlsMiddleware> logger;
public SingleUrlsMiddleware(RequestDelegate next, ILoggerFactory factory)
{
this.next = next;
logger = factory.CreateLogger<SingleUrlsMiddleware>();
}
public async Task Invoke(HttpContext context)
{
var currentUrl = string.Concat(context.Request.Scheme, "://", context.Request.Host, context.Request.Path);
var hostName = context.Request.Host.ToString().ToLowerInvariant();
if (hostName.StartsWith("www."))
{
hostName = hostName.Substring(4);
}
var newUrl = string.Concat("https://", hostName, context.Request.Path);
if (!string.Equals(newUrl, currentUrl, StringComparison.OrdinalIgnoreCase))
{
logger.LogError("Invalid url: {0} instead {1}", currentUrl, newUrl);
context.Response.Redirect(newUrl + context.Request.QueryString, true);
}
else
{
await next(context);
}
}
}
}

5
src/Squidex/Startup.cs

@ -104,11 +104,6 @@ namespace Squidex
loggerFactory.AddConsole(LogLevel.Debug);
loggerFactory.AddDebug();
if (!Environment.IsDevelopment())
{
app.UseMiddleware<SingleUrlsMiddleware>();
}
MapAndUseIdentity(app);
MapAndUseApi(app);
MapAndUseFrontend(app);

5
src/Squidex/appsettings.Production.json

@ -1,5 +0,0 @@
{
"urls": {
"baseUrl": "https://squidex.io"
}
}
Loading…
Cancel
Save