Mercurial
comparison mrjunejune/main.c @ 77:c348ac875294
[Seobeo] Server side rendering.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 31 Dec 2025 14:17:40 -0800 |
| parents | 4532ce6d9eb8 |
| children | e7bf9e002850 |
comparison
equal
deleted
inserted
replaced
| 76:35b1abc37969 | 77:c348ac875294 |
|---|---|
| 5 void handle_sigint(int sig) | 5 void handle_sigint(int sig) |
| 6 { | 6 { |
| 7 printf("Failed\n"); | 7 printf("Failed\n"); |
| 8 stop_server = 1; | 8 stop_server = 1; |
| 9 } | 9 } |
| 10 | |
| 11 Seobeo_Request_Entry* GetHomePage(Seobeo_Request_Entry *req, Dowa_Arena *arena) | |
| 12 { | |
| 13 Seobeo_Request_Entry *resp = NULL; | |
| 14 char *body = Dowa_Arena_Allocate(arena, 10 * 1024); | |
| 15 size_t body_size = 0; | |
| 16 char *file_content = Seobeo_Web_LoadFile("/index.html", &body_size); | |
| 17 snprintf(body, 10 * 1024, file_content); | |
| 18 free(file_content); | |
| 19 | |
| 20 Dowa_HashMap_Push_Arena(resp, "body", body, arena); | |
| 21 return resp; | |
| 22 } | |
| 23 | |
| 24 | |
| 10 | 25 |
| 11 Seobeo_Request_Entry* GetUser(Seobeo_Request_Entry *req, Dowa_Arena *arena) | 26 Seobeo_Request_Entry* GetUser(Seobeo_Request_Entry *req, Dowa_Arena *arena) |
| 12 { | 27 { |
| 13 void *id_kv = Dowa_HashMap_Get_Ptr(req, ":id"); | 28 void *id_kv = Dowa_HashMap_Get_Ptr(req, ":id"); |
| 14 const char *user_id = id_kv ? ((Seobeo_Request_Entry*)id_kv)->value : "unknown"; | 29 const char *user_id = id_kv ? ((Seobeo_Request_Entry*)id_kv)->value : "unknown"; |
| 23 | 38 |
| 24 | 39 |
| 25 int main(void) | 40 int main(void) |
| 26 { | 41 { |
| 27 Seobeo_Router_Init(); | 42 Seobeo_Router_Init(); |
| 28 Seobeo_Router_Register("GET", "/v1/users/:id", GetUser); | 43 Seobeo_Router_Register("GET", "/", GetHomePage); |
| 29 Seobeo_Web_Server_Start("mrjunejune/pages", "6969", SEOBEO_MODE_EDGE, 2); | 44 Seobeo_Web_Server_Start("mrjunejune/pages", "6969", SEOBEO_MODE_EDGE, 2); |
| 30 } | 45 } |