Skip to content

Commit

Permalink
Reduce code duplication when initializing Refresh.HttpsProxy (#594)
Browse files Browse the repository at this point in the history
Since we pass the `BunkumServer` into the `Initialize` function to avoid
a closure allocation, we can use this to our advantage and only have one
function to set up both servers.
  • Loading branch information
jvyden authored Jul 29, 2024
2 parents 7d0a88a + 11ed8c9 commit 6a8e9af
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions Refresh.HttpsProxy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@
// Initialize a Bunkum server for HTTP
BunkumServer httpServer = new BunkumHttpServer(loggerConfiguration);

ProxyConfig config = Config.LoadFromJsonFile<ProxyConfig>("proxy.json", httpsServer.Logger);

httpsServer.Initialize = s =>
Action<BunkumServer> initialize = s =>
{
ProxyConfig config = Config.LoadFromJsonFile<ProxyConfig>("proxy.json", s.Logger);
s.AddMiddleware(new ProxyMiddleware(config));
};

httpServer.Initialize = s =>
{
s.AddMiddleware(new ProxyMiddleware(config));
};
httpsServer.Initialize = initialize;
httpServer.Initialize = initialize;

// Start the server in multi-threaded mode, and let Bunkum manage the rest.
httpsServer.Start();
Expand Down

0 comments on commit 6a8e9af

Please sign in to comment.