Skip to content

Commit

Permalink
listen on ipv6 too
Browse files Browse the repository at this point in the history
  • Loading branch information
laduke committed Mar 5, 2024
1 parent 5820e82 commit 693771a
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions controller/EmbeddedNetworkController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) {
Expand Down

0 comments on commit 693771a

Please sign in to comment.