Skip to content

Commit

Permalink
Minimal APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tratcher committed Nov 15, 2023
1 parent 48e3f7e commit 243477d
Show file tree
Hide file tree
Showing 44 changed files with 585 additions and 1,516 deletions.
11 changes: 0 additions & 11 deletions reverse-proxy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yarp.Kubernetes.Ingress", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "backend", "samples\KubernetesIngress.Sample\backend\backend.csproj", "{EB5663B9-31BA-4930-A302-4B87B8DEB74A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReverseProxy.Minimal.Sample", "samples\ReverseProxy.Minimal.Sample\ReverseProxy.Minimal.Sample.csproj", "{AA34BE13-7193-4036-A886-A7EE6CD36940}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HttpSys.Sample", "HttpSys.Sample", "{34CB3C61-2F42-49FB-ACDC-2B0EC9EE8746}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleHttpSysServer", "samples\ReverseProxy.HttpSysDelegation.Sample\SampleHttpSysServer\SampleHttpSysServer.csproj", "{4A298B67-E7B5-4010-A6F2-5CFBB82BFBB1}"
Expand Down Expand Up @@ -317,14 +315,6 @@ Global
{EB5663B9-31BA-4930-A302-4B87B8DEB74A}.Release|Any CPU.Build.0 = Release|Any CPU
{EB5663B9-31BA-4930-A302-4B87B8DEB74A}.Release|x64.ActiveCfg = Release|Any CPU
{EB5663B9-31BA-4930-A302-4B87B8DEB74A}.Release|x64.Build.0 = Release|Any CPU
{AA34BE13-7193-4036-A886-A7EE6CD36940}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA34BE13-7193-4036-A886-A7EE6CD36940}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA34BE13-7193-4036-A886-A7EE6CD36940}.Debug|x64.ActiveCfg = Debug|Any CPU
{AA34BE13-7193-4036-A886-A7EE6CD36940}.Debug|x64.Build.0 = Debug|Any CPU
{AA34BE13-7193-4036-A886-A7EE6CD36940}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA34BE13-7193-4036-A886-A7EE6CD36940}.Release|Any CPU.Build.0 = Release|Any CPU
{AA34BE13-7193-4036-A886-A7EE6CD36940}.Release|x64.ActiveCfg = Release|Any CPU
{AA34BE13-7193-4036-A886-A7EE6CD36940}.Release|x64.Build.0 = Release|Any CPU
{4A298B67-E7B5-4010-A6F2-5CFBB82BFBB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A298B67-E7B5-4010-A6F2-5CFBB82BFBB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A298B67-E7B5-4010-A6F2-5CFBB82BFBB1}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -407,7 +397,6 @@ Global
{04E87669-7E7B-4217-83A4-EF80B534D14B} = {0B4635FC-8B63-4408-8077-F1CFDA5AB6D7}
{84B920E2-A501-457D-8F1A-9CC7AF8B5F2D} = {04E87669-7E7B-4217-83A4-EF80B534D14B}
{EB5663B9-31BA-4930-A302-4B87B8DEB74A} = {32B6B967-6EAF-42A1-9FD6-A59F752FF76B}
{AA34BE13-7193-4036-A886-A7EE6CD36940} = {149C61A2-D9F8-49B9-9F9B-3C953FEF53AA}
{34CB3C61-2F42-49FB-ACDC-2B0EC9EE8746} = {149C61A2-D9F8-49B9-9F9B-3C953FEF53AA}
{4A298B67-E7B5-4010-A6F2-5CFBB82BFBB1} = {34CB3C61-2F42-49FB-ACDC-2B0EC9EE8746}
{7AA90031-4644-4F38-9790-60E7A7609F58} = {34CB3C61-2F42-49FB-ACDC-2B0EC9EE8746}
Expand Down
38 changes: 18 additions & 20 deletions samples/BasicYarpSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace BasicYARPSample
{
public class Program
{
public static void Main(string[] args)
{
// Create a Kestrel web server, and tell it to use the Startup class
// for the service configuration
var myHostBuilder = Host.CreateDefaultBuilder(args);
myHostBuilder.ConfigureWebHostDefaults(webHostBuilder =>
{
webHostBuilder.UseStartup<Startup>();
});
var myHost = myHostBuilder.Build();
myHost.Run();
}
}
}
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
// Add the reverse proxy capability to the server
builder.Services.AddReverseProxy()
// Initialize the reverse proxy from the "ReverseProxy" section of configuration
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));

var app = builder.Build();

// Register the reverse proxy routes
app.MapReverseProxy();

app.Run();
3 changes: 1 addition & 2 deletions samples/BasicYarpSample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ The proxy will listen to HTTP requests on port 5000, and HTTPS on port 5001. The

## Files
- [BasicYarpSample.csproj](BasicYarpSample.csproj) - A C# project file (conceptually similar to a make file) that tells it to target the .NET 6 runtime, and to reference the proxy library from [nuget](https://www.nuget.org/packages/Yarp.ReverseProxy/) (.NET's package manager).
- [Program.cs](Program.cs) - Provides the main entrypoint for .NET which uses an WebHostBuilder to initialize the server which listens for http requests. Typically, this file does not need to be modified for any proxy scenarios.
- [Startup.cs](Startup.cs) - Provides a class that is used to configure and control how http requests are handled by the server. In this sample, it does the bare minimum of:
- [Program.cs](Program.cs) - Provides the main entrypoint for .NET which uses a WebApplication to initialize the server which listens for http requests. This is also used to configure and control how http requests are handled by the server. In this sample, it does the bare minimum of:
- Adding proxy functionality to the services collection.
- Specifying that the proxy configuration will come from the config file (alternatively it could be specified via code).
- Telling ASP.NET to use its routing service, to register the routes from YARP into its routing table, and use YARP to handle those requests.
Expand Down
47 changes: 0 additions & 47 deletions samples/BasicYarpSample/Startup.cs

This file was deleted.

55 changes: 22 additions & 33 deletions samples/KubernetesIngress.Sample/Combined/Program.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,32 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Diagnostics;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Sinks.SystemConsole.Themes;

namespace Yarp.Kubernetes.Ingress
{
public static class Program
{
public static void Main(string[] args)
{
using var serilog = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
.CreateLogger();
var builder = WebApplication.CreateBuilder(args);

Host.CreateDefaultBuilder(args)
.ConfigureWebHost(webBuilder =>
{
webBuilder.UseKubernetesReverseProxyCertificateSelector();
})
.ConfigureAppConfiguration(config =>
{
config.AddJsonFile("/app/config/yarp.json", optional: true);
})
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddSerilog(serilog, dispose: false);
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
}).Build().Run();
}
}
}
using var serilog = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
.CreateLogger();
builder.Logging.ClearProviders();
builder.Logging.AddSerilog(serilog, dispose: false);

builder.Configuration.AddJsonFile("/app/config/yarp.json", optional: true);
builder.WebHost.UseKubernetesReverseProxyCertificateSelector();
builder.Services.AddKubernetesReverseProxy(builder.Configuration);

var app = builder.Build();

app.MapReverseProxy();

app.Run();
46 changes: 0 additions & 46 deletions samples/KubernetesIngress.Sample/Combined/Startup.cs

This file was deleted.

51 changes: 26 additions & 25 deletions samples/KubernetesIngress.Sample/Ingress/Program.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Diagnostics;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Sinks.SystemConsole.Themes;
using Yarp.Kubernetes.Protocol;

namespace Yarp.Kubernetes.Ingress
{
public static class Program
{
public static void Main(string[] args)
{
using var serilog = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
.CreateLogger();
var builder = WebApplication.CreateBuilder(args);

Host.CreateDefaultBuilder(args)
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddSerilog(serilog, dispose: false);
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
}).Build().Run();
}
}
}
using var serilog = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
.CreateLogger();
builder.Logging.ClearProviders();
builder.Logging.AddSerilog(serilog, dispose: false);

var services = builder.Services;
services.Configure<ReceiverOptions>(builder.Configuration.Bind);
services.AddHostedService<Receiver>();
services.AddReverseProxy()
.LoadFromMessages();

var app = builder.Build();

app.MapReverseProxy();

app.Run();
49 changes: 0 additions & 49 deletions samples/KubernetesIngress.Sample/Ingress/Startup.cs

This file was deleted.

Loading

0 comments on commit 243477d

Please sign in to comment.