diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 4dd091c..1b8e2ad 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -103,6 +103,16 @@ std::string loadCustomTemplate (std::string customIndexPath) { return indexTemplateString; } +inline std::string normalizeRootUrl(std::string rootUrl) +{ + while ( !rootUrl.empty() && rootUrl.back() == '/' ) + rootUrl.pop_back(); + + while ( !rootUrl.empty() && rootUrl.front() == '/' ) + rootUrl = rootUrl.substr(1); + return rootUrl.empty() ? rootUrl : "/" + rootUrl; +} + volatile sig_atomic_t waiting = false; volatile sig_atomic_t libraryMustBeReloaded = false; @@ -393,7 +403,7 @@ int main(int argc, char** argv) exit(1); } - std::string url = "http://" + server.getAddress() + ":" + std::to_string(server.getPort()) + rootLocation; + std::string url = "http://" + server.getAddress() + ":" + std::to_string(server.getPort()) + normalizeRootUrl(rootLocation); std::cout << "The Kiwix server is running and can be accessed in the local network at: " << url << std::endl;