Browse Source

Fix static file loading when using ingress with host (#591)

* fix static files loading when using host in ingress

* formatting

* formatting

* fixing failing tests

* fix tests
pull/600/head
areller 6 years ago
committed by GitHub
parent
commit
5ea1ae0400
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/Microsoft.Tye.Hosting/HttpProxyService.cs
  2. 30
      test/E2ETest/TyeRunTests.cs
  3. 7
      test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/ApplicationC-UI.csproj
  4. 26
      test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/Program.cs
  5. 27
      test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/Properties/launchSettings.json
  6. 34
      test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/Startup.cs
  7. 9
      test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/appsettings.Development.json
  8. 10
      test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/appsettings.json
  9. 1
      test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/wwwroot/index.html
  10. 19
      test/E2ETest/testassets/projects/apps-with-ingress/tye-ui.yaml
  11. 4
      test/E2ETest/testassets/projects/apps-with-ingress/tye.yaml

12
src/Microsoft.Tye.Hosting/HttpProxyService.cs

@ -161,16 +161,8 @@ namespace Microsoft.Tye.Hosting
await context.ProxyRequest(invoker, uri.Uri);
};
IEndpointConventionBuilder conventions = null!;
if (rule.Path != null)
{
conventions = ((IEndpointRouteBuilder)webApp).Map(rule.Path.TrimEnd('/') + "/{**path}", del);
}
else
{
conventions = webApp.MapFallback(del);
}
IEndpointConventionBuilder conventions =
((IEndpointRouteBuilder)webApp).Map((rule.Path?.TrimEnd('/') ?? "") + "/{**path}", del);
if (rule.Host != null)
{

30
test/E2ETest/TyeRunTests.cs

@ -648,6 +648,36 @@ services:
});
}
[Fact]
public async Task IngressStaticFilesTest()
{
using var projectDirectory = CopyTestProjectDirectory("apps-with-ingress");
var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye-ui.yaml"));
var outputContext = new OutputContext(_sink, Verbosity.Debug);
var application = await ApplicationFactory.CreateAsync(outputContext, projectFile);
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (a, b, c, d) => true,
AllowAutoRedirect = true
};
var client = new HttpClient(new RetryHandler(handler));
await RunHostingApplication(application, new HostOptions(), async (app, uri) =>
{
var ingressUri = await GetServiceUrl(client, uri, "ingress");
var htmlRequest = new HttpRequestMessage(HttpMethod.Get,
ingressUri + "/index.html");
htmlRequest.Headers.Host = "ui.example.com";
var htmlResponse = await client.SendAsync(htmlRequest);
htmlResponse.EnsureSuccessStatusCode();
});
}
[ConditionalFact]
[SkipIfDockerNotRunning]
public async Task NginxIngressTest()

7
test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/ApplicationC-UI.csproj

@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>

26
test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/Program.cs

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace ApplicationC_UI
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}

27
test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/Properties/launchSettings.json

@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:28611",
"sslPort": 44364
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"ApplicationC_UI": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

34
test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/Startup.cs

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace ApplicationC_UI
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseStaticFiles();
}
}
}

9
test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/appsettings.Development.json

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

10
test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/appsettings.json

@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

1
test/E2ETest/testassets/projects/apps-with-ingress/ApplicationC-UI/wwwroot/index.html

@ -0,0 +1 @@
Hello world

19
test/E2ETest/testassets/projects/apps-with-ingress/tye-ui.yaml

@ -0,0 +1,19 @@
# tye application configuration file
# read all about it at https://github.com/dotnet/tye
#
# when you've given us a try, we'd love to know what you think:
# https://aka.ms/AA7q20u
#
name: apps-with-ingress-ui
ingress:
- name: ingress
bindings:
- port: 8080
rules:
- host: ui.example.com
service: appC-ui
services:
- name: appC-ui
project: ApplicationC-UI/ApplicationC-UI.csproj
replicas: 2

4
test/E2ETest/testassets/projects/apps-with-ingress/tye.yaml

@ -17,7 +17,7 @@ ingress:
- host: a.example.com
service: appA
- host: b.example.com
service: appB
service: appB
services:
- name: appA
@ -25,4 +25,4 @@ services:
replicas: 2
- name: appB
project: ApplicationB/ApplicationB.csproj
replicas: 2
replicas: 2
Loading…
Cancel
Save