@@ -40,6 +40,7 @@ struct server_params
40
40
{
41
41
std::string hostname = " 127.0.0.1" ;
42
42
std::string public_path = " examples/server/public" ;
43
+ std::string request_path = " " ;
43
44
44
45
int32_t port = 8080 ;
45
46
int32_t read_timeout = 600 ;
@@ -161,6 +162,7 @@ void whisper_print_usage(int /*argc*/, char ** argv, const whisper_params & para
161
162
fprintf (stderr, " --host HOST, [%-7s] Hostname/ip-adress for the server\n " , sparams.hostname .c_str ());
162
163
fprintf (stderr, " --port PORT, [%-7d] Port number for the server\n " , sparams.port );
163
164
fprintf (stderr, " --public PATH, [%-7s] Path to the public folder\n " , sparams.public_path .c_str ());
165
+ fprintf (stderr, " --request-path PATH, [%-7s] Request path for all requests\n " , sparams.request_path .c_str ());
164
166
fprintf (stderr, " --convert, [%-7s] Convert audio to WAV, requires ffmpeg on the server" , sparams.ffmpeg_converter ? " true" : " false" );
165
167
fprintf (stderr, " \n " );
166
168
}
@@ -208,6 +210,7 @@ bool whisper_params_parse(int argc, char ** argv, whisper_params & params, serve
208
210
else if ( arg == " --port" ) { sparams.port = std::stoi (argv[++i]); }
209
211
else if ( arg == " --host" ) { sparams.hostname = argv[++i]; }
210
212
else if ( arg == " --public" ) { sparams.public_path = argv[++i]; }
213
+ else if ( arg == " --request-path" ) { sparams.request_path = argv[++i]; }
211
214
else if ( arg == " --convert" ) { sparams.ffmpeg_converter = true ; }
212
215
else {
213
216
fprintf (stderr, " error: unknown argument: %s\n " , arg.c_str ());
@@ -480,12 +483,12 @@ int main(int argc, char ** argv) {
480
483
std::string const default_content = " <html>hello</html>" ;
481
484
482
485
// this is only called if no index.html is found in the public --path
483
- svr.Get (" /" , [&default_content](const Request &, Response &res){
486
+ svr.Get (sparams. request_path + " /" , [&default_content](const Request &, Response &res){
484
487
res.set_content (default_content, " text/html" );
485
488
return false ;
486
489
});
487
490
488
- svr.Post (" /inference" , [&](const Request &req, Response &res){
491
+ svr.Post (sparams. request_path + " /inference" , [&](const Request &req, Response &res){
489
492
// acquire whisper model mutex lock
490
493
whisper_mutex.lock ();
491
494
@@ -722,7 +725,7 @@ int main(int argc, char ** argv) {
722
725
// return whisper model mutex lock
723
726
whisper_mutex.unlock ();
724
727
});
725
- svr.Post (" /load" , [&](const Request &req, Response &res){
728
+ svr.Post (sparams. request_path + " /load" , [&](const Request &req, Response &res){
726
729
whisper_mutex.lock ();
727
730
if (!req.has_file (" model" ))
728
731
{
@@ -778,11 +781,11 @@ int main(int argc, char ** argv) {
778
781
res.status = 500 ;
779
782
});
780
783
781
- svr.set_error_handler ([](const Request &, Response &res) {
784
+ svr.set_error_handler ([](const Request &req , Response &res) {
782
785
if (res.status == 400 ) {
783
786
res.set_content (" Invalid request" , " text/plain" );
784
787
} else if (res.status != 500 ) {
785
- res.set_content (" File Not Found" , " text/plain" );
788
+ res.set_content (" File Not Found ( " + req. path + " ) " , " text/plain" );
786
789
res.status = 404 ;
787
790
}
788
791
});
0 commit comments