Skip to content

Commit 0b7efbe

Browse files
committed
server: add external ui support for dev
1 parent 6cabd95 commit 0b7efbe

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

examples/server/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,25 @@ void start_server(SDParams params) {
17801780
res.set_redirect("/index.html");
17811781
});
17821782

1783+
svr->Get("/dev-index", [](const httplib::Request& req, httplib::Response& res) {
1784+
try {
1785+
std::string def_frontend_path = "examples/server/frontend.html";
1786+
std::string html = "";
1787+
std::ifstream file(def_frontend_path);
1788+
if (file.is_open()) {
1789+
std::stringstream buffer;
1790+
buffer << file.rdbuf();
1791+
html = buffer.str();
1792+
file.close();
1793+
} else {
1794+
html = "Error: Unable to open file " + def_frontend_path;
1795+
}
1796+
res.set_content(html, "text/html");
1797+
} catch (const std::exception& e) {
1798+
res.set_content("Error loading page", "text/plain");
1799+
}
1800+
});
1801+
17831802
// bind HTTP listen port, run the HTTP server in a thread
17841803
if (!svr->bind_to_port(params.host, params.port)) {
17851804
// TODO: Error message

0 commit comments

Comments
 (0)