@@ -336,6 +336,7 @@ typedef struct _webui_window_t {
336336 const char * html ;
337337 const char * user_index_file ;
338338 const char * user_index_file_encoded ;
339+ bool allow_index_fallback ;
339340 char * server_root_path ;
340341 #ifdef _WIN32
341342 HANDLE server_thread ;
@@ -5425,10 +5426,12 @@ static int _webui_external_file_handler(_webui_window_t* win, struct mg_connecti
54255426 }
54265427 }
54275428
5428- index_files [index_files_len ++ ] = "index.html" ;
5429- index_files [index_files_len ++ ] = "index.htm" ;
5430- index_files [index_files_len ++ ] = "index.ts" ;
5431- index_files [index_files_len ++ ] = "index.js" ;
5429+ if (win -> allow_index_fallback ) {
5430+ index_files [index_files_len ++ ] = "index.html" ;
5431+ index_files [index_files_len ++ ] = "index.htm" ;
5432+ index_files [index_files_len ++ ] = "index.ts" ;
5433+ index_files [index_files_len ++ ] = "index.js" ;
5434+ }
54325435
54335436 char base_url [WEBUI_MAX_PATH ];
54345437 if (strcmp (url , "/" ) == 0 ) {
@@ -8860,6 +8863,7 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien
88608863 if (!keep_user_index_file ) {
88618864 win -> user_index_file = NULL ;
88628865 win -> user_index_file_encoded = NULL ;
8866+ win -> allow_index_fallback = false;
88638867 }
88648868
88658869 // Get network ports
@@ -8924,6 +8928,7 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien
89248928
89258929 // Show a window using a local folder
89268930 win -> is_embedded_html = false;
8931+ win -> allow_index_fallback = true;
89278932
89288933 // Set window URL
89298934 window_url = win -> url ;
@@ -8934,6 +8939,7 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien
89348939 win -> is_embedded_html = false;
89358940 win -> user_index_file = content ;
89368941 win -> user_index_file_encoded = _webui_url_encode (content );
8942+ win -> allow_index_fallback = false;
89378943
89388944 // Generate the URL
89398945 size_t bf_len = (64 + _webui_strlen (win -> user_index_file_encoded ));
@@ -9944,15 +9950,23 @@ static int _webui_http_handler(struct mg_connection* client, void * _win) {
99449950
99459951 // Looking for index file and redirect
99469952
9947- const char * index_files [] = {
9948- win -> user_index_file , // User-defined index file
9949- "index.html" , "index.htm" , "index.ts" , "index.js"
9950- };
9953+ const char * index_files [5 ];
9954+ size_t index_files_len = 0 ;
9955+
9956+ if (!_webui_is_empty (win -> user_index_file )) {
9957+ index_files [index_files_len ++ ] = win -> user_index_file ;
9958+ }
9959+ if (win -> allow_index_fallback ) {
9960+ index_files [index_files_len ++ ] = "index.html" ;
9961+ index_files [index_files_len ++ ] = "index.htm" ;
9962+ index_files [index_files_len ++ ] = "index.ts" ;
9963+ index_files [index_files_len ++ ] = "index.js" ;
9964+ }
99519965
99529966 // [Path][Sep][File Name]
99539967 size_t bf_len = (_webui_strlen (win -> server_root_path ) + 1 + 24 );
99549968 char * index_path = (char * )_webui_malloc (bf_len );
9955- for (size_t i = 0 ; i < ( sizeof ( index_files ) / sizeof ( index_files [ 0 ])) ; i ++ ) {
9969+ for (size_t i = 0 ; i < index_files_len ; i ++ ) {
99569970 WEBUI_SN_PRINTF_DYN (index_path , bf_len , "%s%s%s" ,
99579971 win -> server_root_path , os_sep , index_files [i ]
99589972 );
@@ -10072,10 +10086,12 @@ static int _webui_http_handler(struct mg_connection* client, void * _win) {
1007210086 }
1007310087 }
1007410088
10075- index_files [index_files_len ++ ] = "index.html" ;
10076- index_files [index_files_len ++ ] = "index.htm" ;
10077- index_files [index_files_len ++ ] = "index.ts" ;
10078- index_files [index_files_len ++ ] = "index.js" ;
10089+ if (win -> allow_index_fallback ) {
10090+ index_files [index_files_len ++ ] = "index.html" ;
10091+ index_files [index_files_len ++ ] = "index.htm" ;
10092+ index_files [index_files_len ++ ] = "index.ts" ;
10093+ index_files [index_files_len ++ ] = "index.js" ;
10094+ }
1007910095
1008010096 // [Path][Sep][File Name]
1008110097 size_t bf_len = (_webui_strlen (folder_path ) + 1 + 24 );
0 commit comments