Skip to content

Commit

Permalink
Upgrade to .net 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aimenux committed Aug 10, 2024
1 parent 52f392e commit bb119b1
Show file tree
Hide file tree
Showing 32 changed files with 264 additions and 229 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

#JetBrains
.idea/
4 changes: 2 additions & 2 deletions AppGateway/AppGateway.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Yarp.ReverseProxy" Version="2.0.1" />
<PackageReference Include="Yarp.ReverseProxy" Version="2.1.0" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions AppGateway/AppGateway.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
###

@LocalUrl = https://localhost:5000

### Get random-route

GET {{LocalUrl}}/api
Accept: application/json

### Get customers-route

GET {{LocalUrl}}/customers
Accept: application/json

### Get orders-route

GET {{LocalUrl}}/orders
Accept: application/json

### Get products-route

GET {{LocalUrl}}/products
Accept: application/json

###
10 changes: 10 additions & 0 deletions AppGateway/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace AppGateway;

public static class Constants
{
public const string ReverseProxySectionName = "ReverseProxy";

public const string RateLimitingPolicyName = "RateLimiting";

public const string OutputCachePolicyName = "OutputCache";
}
6 changes: 4 additions & 2 deletions AppGateway/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace AppGateway;

public static class Program
{
public static void Main(string[] args)
public static async Task Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
using var host = CreateHostBuilder(args).Build();
await host.RunAsync();
}

private static IHostBuilder CreateHostBuilder(string[] args) =>
Expand Down
55 changes: 43 additions & 12 deletions AppGateway/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
using System;
using System.Threading.RateLimiting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpLogging;
using Microsoft.AspNetCore.RateLimiting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace AppGateway;

public class Startup
public class Startup(IConfiguration configuration)
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();

services.AddHttpLogging(options =>
{
options.LoggingFields = HttpLoggingFields.All;
options.CombineLogs = true;
});

services.AddOutputCache(options =>
{
options.AddPolicy(Constants.OutputCachePolicyName, builder =>
{
builder.Expire(TimeSpan.FromSeconds(1));
});
});

services.AddRateLimiter(rateLimiterOptions =>
{
rateLimiterOptions.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
rateLimiterOptions.AddFixedWindowLimiter(Constants.RateLimitingPolicyName, options =>
{
options.PermitLimit = 5;
options.Window = TimeSpan.FromSeconds(10);
options.QueueLimit = 0;
options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
});
});

services
.AddReverseProxy()
.LoadFromConfig(Configuration.GetSection("ReverseProxy"));
.LoadFromConfig(configuration.GetSection(Constants.ReverseProxySectionName));
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Expand All @@ -32,16 +55,24 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseDeveloperExceptionPage();
}

app.UseHttpsRedirection();
app.UseHttpLogging();

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthentication();

app.UseAuthorization();


app.UseOutputCache();

app.UseRateLimiter();

app.UseEndpoints(endpoints =>
{
endpoints.MapGet("", ctx => ctx.Response.WriteAsync("App Gateway"));
endpoints.MapReverseProxy();
endpoints.MapReverseProxy().CacheOutput(Constants.OutputCachePolicyName);
});
}
}
71 changes: 0 additions & 71 deletions AppGateway/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,7 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"ReverseProxy": {
"Routes": {
"random-route": {
"ClusterId": "random-cluster",
"Match": {
"Path": "/api/{**catchall}"
},
"Transforms": [
{
"PathRemovePrefix": "/api"
}
]
},
"customers-route": {
"ClusterId": "customers-cluster",
"Match": {
"Path": "/customers/{**catchall}"
}
},
"orders-route": {
"ClusterId": "orders-cluster",
"Match": {
"Path": "/orders/{**catchall}"
}
},
"products-route": {
"ClusterId": "products-cluster",
"Match": {
"Path": "/products/{**catchall}"
}
}
},
"Clusters": {
"random-cluster": {
"LoadBalancingPolicy": "RoundRobin",
"Destinations": {
"random-cluster/destination1": {
"Address": "https://localhost:5010/api/customers"
},
"random-cluster/destination2": {
"Address": "https://localhost:5020/api/orders"
},
"random-cluster/destination3": {
"Address": "https://localhost:5030/api/products"
}
}
},
"customers-cluster": {
"Destinations": {
"customers-cluster/destination1": {
"Address": "https://localhost:5010/api"
}
}
},
"orders-cluster": {
"Destinations": {
"orders-cluster/destination1": {
"Address": "https://localhost:5020/api"
}
}
},
"products-cluster": {
"Destinations": {
"products-cluster/destination1": {
"Address": "https://localhost:5030/api"
}
}
}
}
}
}
77 changes: 75 additions & 2 deletions AppGateway/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,82 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
"ReverseProxy": {
"Routes": {
"random-route": {
"ClusterId": "random-cluster",
"RateLimiterPolicy": "RateLimiting",
"Match": {
"Path": "/api/{**catch-all}",
"Methods": [ "GET" ]
},
"Transforms": [
{
"PathRemovePrefix": "/api"
}
]
},
"customers-route": {
"ClusterId": "customers-cluster",
"Match": {
"Path": "/customers/{**catch-all}",
"Methods": [ "GET" ]
}
},
"orders-route": {
"ClusterId": "orders-cluster",
"Match": {
"Path": "/orders/{**catch-all}",
"Methods": [ "GET" ]
}
},
"products-route": {
"ClusterId": "products-cluster",
"Match": {
"Path": "/products/{**catch-all}",
"Methods": [ "GET" ]
}
}
},
"Clusters": {
"random-cluster": {
"LoadBalancingPolicy": "RoundRobin",
"Destinations": {
"random-cluster/destination1": {
"Address": "https://localhost:5010/api/customers"
},
"random-cluster/destination2": {
"Address": "https://localhost:5020/api/orders"
},
"random-cluster/destination3": {
"Address": "https://localhost:5030/api/products"
}
}
},
"customers-cluster": {
"Destinations": {
"customers-cluster/destination1": {
"Address": "https://localhost:5010/api"
}
}
},
"orders-cluster": {
"Destinations": {
"orders-cluster/destination1": {
"Address": "https://localhost:5020/api"
}
}
},
"products-cluster": {
"Destinations": {
"products-cluster/destination1": {
"Address": "https://localhost:5030/api"
}
}
}
}
}
}
Loading

0 comments on commit bb119b1

Please sign in to comment.