Skip to content

Commit

Permalink
Increased configuration in middleware.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCiliaVincenti committed Dec 13, 2022
1 parent 5d3ee2d commit dec5958
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Samples/CertbotSample/CertbotSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<PackageReference Include="NetworkPorts" Version="1.1.1" />
<PackageReference Include="TlsCertificateLoader" Version="2.1.2" />
<PackageReference Include="TlsCertificateLoader" Version="2.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\TlsCertificateLoader\TlsCertificateLoader.csproj" />
<PackageReference Include="TlsCertificateLoader" Version="2.2.0" />
</ItemGroup>

</Project>
19 changes: 17 additions & 2 deletions Samples/CertbotSampleUsingMiddleware/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Hosting;
using Microsoft.Net.Http.Headers;
using NetworkPorts;
using System;
using System.Net;
using TlsCertificateLoader.Extensions;

var host = Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureServices(services => services.AddTlsCertificateLoader("mydomain.tld", "www.mydomain.tld", "/etc/letsencrypt"));
webBuilder.ConfigureServices(services => services.AddTlsCertificateLoader("mydomain.tld", "www.mydomain.tld", "/etc/letsencrypt", o =>
{
o.IncludeSubDomains = false;
o.Preload = true;
o.HstsEnabled = true;
o.MaxAge = TimeSpan.FromDays(365 * 2);
}));
webBuilder.Configure(configureApp => configureApp.UseTlsCertificateLoader(o =>
{
o.UseDefaultFiles = true;
Expand All @@ -31,7 +39,14 @@
o.RedirectHttpToHttps = true;
o.RedirectWwwSubdomainToDomain = true;
}));
webBuilder.UseTlsCertificateLoader(o => o.IPAddress = new IPAddress(0));
webBuilder.UseTlsCertificateLoader(o =>
{
o.HttpPort = NetworkPort.Http;
o.HttpsPort = NetworkPort.Https;
o.HttpProtocols = HttpProtocols.Http1AndHttp2AndHttp3;
o.ListenOnUnencryptedHttp = true;
o.IPAddress = new IPAddress(0);
});
}).Build();

await host.RunAsync();

0 comments on commit dec5958

Please sign in to comment.