Skip to content

Commit

Permalink
Added code for storing hostname with Integrated Middleware. See #986
Browse files Browse the repository at this point in the history
  • Loading branch information
tidyui committed Jan 16, 2020
1 parent ed28e8b commit 341a749
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/Piranha.AspNetCore/IntegratedMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,21 @@ public override async Task Invoke(HttpContext context, IApi api, IApplicationSer
//
Site site = null;

var hostname = context.Request.Host.Host;

if (_config.UseSiteRouting)
{
// Try to get the requested site by hostname & prefix
if (segments.Length > 0)
{
site = await api.Sites.GetByHostnameAsync($"{context.Request.Host.Host}/{segments[0]}")
var prefixedHostname = $"{hostname}/{segments[0]}";
site = await api.Sites.GetByHostnameAsync(prefixedHostname)
.ConfigureAwait(false);

if (site != null)
{
context.Request.Path = "/" + string.Join("/", segments.Skip(1));
hostname = prefixedHostname;
pos = 1;
}
}
Expand Down Expand Up @@ -106,6 +110,9 @@ public override async Task Invoke(HttpContext context, IApi api, IApplicationSer
}
}

// Store hostname
service.Hostname = hostname;

//
// Check if we shouldn't handle empty requests for start page
//
Expand Down

0 comments on commit 341a749

Please sign in to comment.