Mercurial
changeset 77:c348ac875294
[Seobeo] Server side rendering.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 31 Dec 2025 14:17:40 -0800 |
| parents | 35b1abc37969 |
| children | e7bf9e002850 |
| files | mrjunejune/main.c mrjunejune/pages/index.html seobeo/s_web.c seobeo/seobeo.h |
| diffstat | 4 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mrjunejune/main.c Wed Dec 31 14:11:21 2025 -0800 +++ b/mrjunejune/main.c Wed Dec 31 14:17:40 2025 -0800 @@ -8,6 +8,21 @@ stop_server = 1; } +Seobeo_Request_Entry* GetHomePage(Seobeo_Request_Entry *req, Dowa_Arena *arena) +{ + Seobeo_Request_Entry *resp = NULL; + char *body = Dowa_Arena_Allocate(arena, 10 * 1024); + size_t body_size = 0; + char *file_content = Seobeo_Web_LoadFile("/index.html", &body_size); + snprintf(body, 10 * 1024, file_content); + free(file_content); + + Dowa_HashMap_Push_Arena(resp, "body", body, arena); + return resp; +} + + + Seobeo_Request_Entry* GetUser(Seobeo_Request_Entry *req, Dowa_Arena *arena) { void *id_kv = Dowa_HashMap_Get_Ptr(req, ":id"); @@ -25,6 +40,6 @@ int main(void) { Seobeo_Router_Init(); - Seobeo_Router_Register("GET", "/v1/users/:id", GetUser); + Seobeo_Router_Register("GET", "/", GetHomePage); Seobeo_Web_Server_Start("mrjunejune/pages", "6969", SEOBEO_MODE_EDGE, 2); }
--- a/mrjunejune/pages/index.html Wed Dec 31 14:11:21 2025 -0800 +++ b/mrjunejune/pages/index.html Wed Dec 31 14:17:40 2025 -0800 @@ -6,7 +6,7 @@ </head> <body> <main> - <div id="header"></div> + <^ parts/header.html ^> <h1> Useful scripts </h1> <ul> <li> <a href="/resume"> Resume </a> </li> @@ -14,5 +14,4 @@ </ul> </main> </body> - <script src="index.js"></script> </html>
--- a/seobeo/s_web.c Wed Dec 31 14:11:21 2025 -0800 +++ b/seobeo/s_web.c Wed Dec 31 14:17:40 2025 -0800 @@ -29,7 +29,7 @@ ); } -static char* Seobeo_Web_LoadFile(const char *file_path, size_t *p_file_size) +char* Seobeo_Web_LoadFile(const char *file_path, size_t *p_file_size) { printf("file_path: %s\n", file_path); char full_path[1024];
--- a/seobeo/seobeo.h Wed Dec 31 14:11:21 2025 -0800 +++ b/seobeo/seobeo.h Wed Dec 31 14:17:40 2025 -0800 @@ -74,6 +74,7 @@ extern Seobeo_Route_Handler Seobeo_Router_Find_Handler(const char *method, const char *path, Seobeo_Request_Entry **pp_request_map, Dowa_Arena *p_arena); /* Send HTTP response from response map (internal use) */ extern void Seobeo_Router_Send_Response(Seobeo_Handle *p_handle, Seobeo_Request_Entry *p_response_map, Dowa_Arena *p_arena); +extern char *Seobeo_Web_LoadFile(const char *file_path, size_t *p_file_size) // --- Helper functions --- // /* Destroy handle. It will handle all NULL poointers. */