Files
hmail/server/server.c

32 lines
971 B
C
Raw Normal View History

2026-04-10 22:40:12 -05:00
#include "include/mongoose.h"
2026-04-17 20:32:46 -05:00
#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);
}
2026-04-10 22:40:12 -05:00
static void ev_handler(struct mg_connection *c, int ev, void *ev_data) {
2026-04-11 15:08:22 -05:00
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *)ev_data;
2026-04-17 20:32:46 -05:00
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;
}
2026-04-11 15:08:22 -05:00
}
mg_http_reply(c, 200, "", "%s", "<html>Hello world</html>");
2026-04-10 22:40:12 -05:00
}
}
int main() {
2026-04-11 15:08:22 -05:00
struct mg_mgr mgr;
mg_mgr_init(&mgr);
mg_http_listen(&mgr, "http://0.0.0.0:8000", ev_handler, NULL);
for (;;) {
mg_mgr_poll(&mgr, 100);
}
return 0;
2026-04-10 22:40:12 -05:00
}