add request url parsing / handling
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
#include "include/mongoose.h"
|
||||
#include "include/array.h"
|
||||
|
||||
static void api_handler(struct mg_connection *c, int ev, struct mg_http_message *hm) {
|
||||
mg_http_reply(c, 200, "", "%s : %.*s", "api route response", hm->uri.len, hm->uri.buf);
|
||||
}
|
||||
|
||||
static void ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_HTTP_MSG) {
|
||||
struct mg_http_message *hm = (struct mg_http_message *)ev_data;
|
||||
printf("URL: %.*s\n", (int)hm->uri.len, hm->uri.buf);
|
||||
if (mg_match(hm->uri, mg_str("/api/test"), NULL)) {
|
||||
mg_http_reply(c, 200, "", "%s", "test");
|
||||
return;
|
||||
|
||||
array_mg_str path_array = {0};
|
||||
split_mg_str(&hm->uri, '/', &path_array);
|
||||
if (path_array.count > 0) {
|
||||
if (mg_match(path_array.items[0], mg_str("api"), NULL)) {
|
||||
api_handler(c, ev, hm);
|
||||
return;
|
||||
}
|
||||
}
|
||||
mg_http_reply(c, 200, "", "%s", "<html>Hello world</html>");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user