create base app with custom routes

This commit is contained in:
2026-04-10 22:40:12 -05:00
parent ed997f7fc4
commit 599ea0fbb6
6 changed files with 33787 additions and 0 deletions

0
client/Makefile Normal file
View File

1
server/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build/

20
server/Makefile Normal file
View File

@@ -0,0 +1,20 @@
CC = gcc
INCLUDE := include
CFLAGS = -Wall -I$(INCLUDE)
BUILD_DIR := build
all: server
server: $(BUILD_DIR)/server.o $(BUILD_DIR)/mongoose.o
$(CC) $(CFLAGS) -o $(BUILD_DIR)/server $(BUILD_DIR)/server.o $(BUILD_DIR)/mongoose.o
$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
clean:
rm -rf $(BUILD_DIR)

4145
server/include/mongoose.h Normal file

File diff suppressed because it is too large Load Diff

29598
server/mongoose.c Normal file

File diff suppressed because it is too large Load Diff

23
server/server.c Normal file
View File

@@ -0,0 +1,23 @@
#include "include/mongoose.h"
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;
}
mg_http_reply(c, 200, "", "%s", "<html>Hello world</html>");
}
}
int main() {
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;
}