diff options
| author | Stefan Boberg <[email protected]> | 2026-02-25 10:15:41 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-02-25 10:15:41 +0100 |
| commit | 241e4faf64be83711dc509ad8a25ff4e8ae95c12 (patch) | |
| tree | 36d4168f89999942060d6c07e41c84a84512b3e9 /src/zenhttp/httpserver.cpp | |
| parent | Fix zencore bugs and propagate content type through IoBufferBuilder (#783) (diff) | |
| download | zen-241e4faf64be83711dc509ad8a25ff4e8ae95c12.tar.xz zen-241e4faf64be83711dc509ad8a25ff4e8ae95c12.zip | |
HttpService/Frontend improvements (#782)
- zenhttp: added `GetServiceUri()`/`GetExternalHost()`
- enables code to quickly generate an externally reachable URI for a given service
- frontend: improved Uri handling (better defaults)
- added support for 404 page (to make it easier to find a good URL)
Diffstat (limited to 'src/zenhttp/httpserver.cpp')
| -rw-r--r-- | src/zenhttp/httpserver.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp index f2fe4738f..3cefa0ad8 100644 --- a/src/zenhttp/httpserver.cpp +++ b/src/zenhttp/httpserver.cpp @@ -23,6 +23,7 @@ #include <zencore/logging.h> #include <zencore/stream.h> #include <zencore/string.h> +#include <zencore/system.h> #include <zencore/testing.h> #include <zencore/thread.h> #include <zenhttp/packageformat.h> @@ -1014,7 +1015,28 @@ HttpRequestRouter::HandleRequest(zen::HttpServerRequest& Request) int HttpServer::Initialize(int BasePort, std::filesystem::path DataDir) { - return OnInitialize(BasePort, std::move(DataDir)); + m_EffectivePort = OnInitialize(BasePort, std::move(DataDir)); + m_ExternalHost = OnGetExternalHost(); + return m_EffectivePort; +} + +std::string +HttpServer::OnGetExternalHost() const +{ + return GetMachineName(); +} + +std::string +HttpServer::GetServiceUri(const HttpService* Service) const +{ + if (Service) + { + return fmt::format("http://{}:{}{}", m_ExternalHost, m_EffectivePort, Service->BaseUri()); + } + else + { + return fmt::format("http://{}:{}", m_ExternalHost, m_EffectivePort); + } } void |