added cors headers and colors log
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 10s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 21s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Failing after 8s

This commit is contained in:
wt committed 2025-08-28 18:02:18 +07:00
1 parent 5840fded28
commit 28655e7b46
13 files changed
+160 -56

No files matched your search

+6
View File
@@ -1,5 +1,7 @@
#include <colors.h>
#include <mongoose.h>
#include <sqlite3.h>
#include "cors.h"
#include "database.h"
#include "route.h"
#include "user.h"
@@ -11,6 +13,7 @@ static void root_handler(struct mg_connection *c, struct mg_http_message *hm) {
static const struct route routes[] = {
{"GET", "/#", root_handler},
{"OPTIONS", "/#", set_cors_headers},
{"POST", "/api/token", get_token},
{"POST", "/api/token/verify", verify_token},
{"POST", "/api/users", get_all_users},
@@ -30,6 +33,8 @@ void ev_handler(struct mg_connection *c, int ev, void *ev_data) {
for (int i = 0; routes[i].path != nullptr; i++) {
if (mg_match(hm->uri, mg_str(routes[i].path), nullptr) &&
mg_match(hm->method, mg_str(routes[i].method), nullptr)) {
mg_log("%s%.*s %s%.*s%s", GREEN, hm->uri.len, hm->uri.buf, BWHITE,
hm->method.len, hm->method.buf, RESET);
routes[i].handler(c, hm);
route_found = true;
break;
@@ -48,6 +53,7 @@ int main(void) {
db_get_users_from_file("users.json");
struct mg_mgr mgr;
mg_log_set(MG_LL_DEBUG);
mg_mgr_init(&mgr);
mg_http_listen(&mgr, "http://0.0.0.0:8222", ev_handler, nullptr);
while (true) {