@@ -104,6 +104,7 @@ std::string iso_timestamp_now() {
104104struct SDSvrParams {
105105 std::string listen_ip = " 127.0.0.1" ;
106106 int listen_port = 1234 ;
107+ std::string serve_html_path;
107108 bool normal_exit = false ;
108109 bool verbose = false ;
109110 bool color = false ;
@@ -115,7 +116,11 @@ struct SDSvrParams {
115116 {" -l" ,
116117 " --listen-ip" ,
117118 " server listen ip (default: 127.0.0.1)" ,
118- &listen_ip}};
119+ &listen_ip},
120+ {" " ,
121+ " --serve-html-path" ,
122+ " path to HTML file to serve at root (optional)" ,
123+ &serve_html_path}};
119124
120125 options.int_options = {
121126 {" " ,
@@ -159,6 +164,11 @@ struct SDSvrParams {
159164 LOG_ERROR (" error: listen_port should be in the range [0, 65535]" );
160165 return false ;
161166 }
167+
168+ if (!serve_html_path.empty () && !fs::exists (serve_html_path)) {
169+ LOG_ERROR (" error: serve_html_path file does not exist: %s" , serve_html_path.c_str ());
170+ return false ;
171+ }
162172 return true ;
163173 }
164174
@@ -167,6 +177,7 @@ struct SDSvrParams {
167177 oss << " SDSvrParams {\n "
168178 << " listen_ip: " << listen_ip << " ,\n "
169179 << " listen_port: \" " << listen_port << " \" ,\n "
180+ << " serve_html_path: \" " << serve_html_path << " \" ,\n "
170181 << " }" ;
171182 return oss.str ();
172183 }
@@ -312,7 +323,18 @@ int main(int argc, const char** argv) {
312323
313324 // health
314325 svr.Get (" /" , [&](const httplib::Request&, httplib::Response& res) {
315- res.set_content (R"( {"ok":true,"service":"sd-cpp-http"})" , " application/json" );
326+ if (!svr_params.serve_html_path .empty ()) {
327+ std::ifstream file (svr_params.serve_html_path );
328+ if (file) {
329+ std::string content ((std::istreambuf_iterator<char >(file)), std::istreambuf_iterator<char >());
330+ res.set_content (content, " text/html" );
331+ } else {
332+ res.status = 500 ;
333+ res.set_content (" Error: Unable to read HTML file" , " text/plain" );
334+ }
335+ } else {
336+ res.set_content (" Stable Diffusion Server is running" , " text/plain" );
337+ }
316338 });
317339
318340 // models endpoint (minimal)
0 commit comments