diff --git a/.gitignore b/.gitignore index c9f9ab88..58771a6e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ bin/ target/ frameworks/blitz/zig-linux-* frameworks/blitz/.zig-cache + +# IDE settings +*.user \ No newline at end of file diff --git a/frameworks/genhttp/Program.cs b/frameworks/genhttp/Program.cs index 9ba1d467..ef623ccb 100644 --- a/frameworks/genhttp/Program.cs +++ b/frameworks/genhttp/Program.cs @@ -1,13 +1,25 @@ using System.Net; - +using System.Security.Cryptography.X509Certificates; using genhttp; using GenHTTP.Engine.Internal; +using GenHTTP.Modules.Compression; + +var certPath = Environment.GetEnvironmentVariable("TLS_CERT") ?? "/certs/server.crt"; +var keyPath = Environment.GetEnvironmentVariable("TLS_KEY") ?? "/certs/server.key"; +var hasCert = File.Exists(certPath) && File.Exists(keyPath); var app = Project.Create(); -var host = Host.Create().Handler(app); +var host = Host.Create() + .Handler(app) + .Compression(); host.Bind(IPAddress.Any, 8080); +if (hasCert) +{ + host.Bind(IPAddress.Any, 8443, X509Certificate2.CreateFromPemFile(certPath, keyPath)); +} + await host.RunAsync(); \ No newline at end of file diff --git a/frameworks/genhttp/Project.cs b/frameworks/genhttp/Project.cs index e361a9b5..670bbad2 100644 --- a/frameworks/genhttp/Project.cs +++ b/frameworks/genhttp/Project.cs @@ -74,8 +74,6 @@ private static LayoutBuilder AddCompression(this LayoutBuilder app) { var service = ServiceResource.From().ExecutionMode(ExecutionMode.Auto); - service.Add(CompressedContent.Default()); - return app.Add("compression", service); }