diff --git a/examples/http-server/Makefile b/examples/http-server/Makefile index 90a85f38..528fc622 100644 --- a/examples/http-server/Makefile +++ b/examples/http-server/Makefile @@ -19,7 +19,7 @@ mingw: gcc ../../mongoose.c main.c -I../.. -W -Wall -DMG_ENABLE_IPV6=1 -DMG_ENABLE_LINES=1 -D_POSIX_C_SOURCE=200000L -lws2_32 -o mongoose.exe linux: example -linux: CFLAGS += -O2 +#linux: CFLAGS += -O2 -fsanitize=address,undefined,shift,null,return,bounds,alignment,object-size,bool,enum -static-libasan linux: CC = $(LIN) cc clean: diff --git a/examples/timers/main.c b/examples/timers/main.c index 686d9611..e6624e3d 100644 --- a/examples/timers/main.c +++ b/examples/timers/main.c @@ -13,13 +13,20 @@ #include "mongoose.h" static const char *s_listen_on = "http://localhost:8000"; +static const char *s_web_root = "web_root"; // This RESTful server implements the following endpoints: static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { if (ev == MG_EV_HTTP_MSG) { struct mg_http_message *hm = (struct mg_http_message *) ev_data; - mg_ws_upgrade(c, hm, NULL); - c->label[0] = 'W'; // Set some unique mark on a connection + if (mg_http_match_uri(hm, "/websocket")) { + mg_ws_upgrade(c, hm, NULL); + c->label[0] = 'W'; // Set some unique mark on a connection + } else { + // Serve static files + struct mg_http_serve_opts opts = {.root_dir = s_web_root}; + mg_http_serve_dir(c, ev_data, &opts); + } } else if (ev == MG_EV_WS_MSG) { // Got websocket frame. Received data is wm->data. Echo it back! struct mg_ws_message *wm = (struct mg_ws_message *) ev_data; diff --git a/examples/timers/web_root/index.html b/examples/timers/web_root/index.html new file mode 100644 index 00000000..f0546681 --- /dev/null +++ b/examples/timers/web_root/index.html @@ -0,0 +1,34 @@ + + + +

Websocket test client

+ + +
 
+ + +
Event log:
+
+ + +