From 693771a1a41f753e8550b6d4ab21868db1364269 Mon Sep 17 00:00:00 2001 From: travisladuke Date: Tue, 5 Mar 2024 15:42:19 -0800 Subject: [PATCH] listen on ipv6 too --- controller/EmbeddedNetworkController.cpp | 27 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index fdebc758b..03d000385 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -880,22 +880,24 @@ void EmbeddedNetworkController::configureHTTPControlPlane( static char appUiDir[16384]; sprintf(appUiDir,"%s/%s",_ztPath.c_str(),appUiPath.c_str()); - - //static file server for controller-ui auto ret = s.set_mount_point(appUiPath, appUiDir); + sv6.set_mount_point(appUiPath, appUiDir); if (!ret) { fprintf(stderr, "Mounting app directory failed. Creating it. Path: %s - Dir: %s\n", appUiPath.c_str(), appUiDir); if (!OSUtils::mkdir(appUiDir)) { fprintf(stderr, "Could not create app directory either. Path: %s - Dir: %s\n", appUiPath.c_str(), appUiDir); } else { ret = s.set_mount_point(appUiPath, appUiDir); + sv6.set_mount_point(appUiPath, appUiDir); if (!ret) { fprintf(stderr, "Really could not create and mount directory. Path: %s - Dir: %s\nWeb apps won't work.\n", appUiPath.c_str(), appUiDir); } } - } else { - // fallback to index.html for unknown paths/files - s.Get(appUiPath + R"(/(\w+)/(.*))", [&](const httplib::Request& req, httplib::Response& res) { + } + + if (ret) { + //static file server for controller-ui + auto indexFallbackGet = [&, setContent](const httplib::Request &req, httplib::Response &res) { auto match = req.matches[1]; if (match.matched) { char indexHtmlPath[16384]; @@ -913,13 +915,20 @@ void EmbeddedNetworkController::configureHTTPControlPlane( res.status = 500; return; } - }); + }; - // auto fix no trailing slash by redirecting - s.Get(appUiPath + R"(/(\w+))", [&](const httplib::Request& req, httplib::Response& res) { + auto slashRedirect = [&, setContent](const httplib::Request &req, httplib::Response &res) { res.status = 301; res.set_header("location", req.path + "/"); - }); + }; + + // fallback to index.html for unknown paths/files + s.Get(appUiPath + R"(/(\w+)/(.*))", indexFallbackGet); + sv6.Get(appUiPath + R"(/(\w+)/(.*))", indexFallbackGet); + + // auto fix no trailing slash by redirecting + s.Get(appUiPath + R"(/(\w+))", slashRedirect); + sv6.Get(appUiPath + R"(/(\w+))", slashRedirect); } auto controllerGet = [&, setContent](const httplib::Request &req, httplib::Response &res) {