view 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
line wrap: on
line source

#include "seobeo/seobeo.h"

volatile sig_atomic_t stop_server = 0;

void handle_sigint(int sig)
{
  printf("Failed\n");
  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");
  const char *user_id = id_kv ? ((Seobeo_Request_Entry*)id_kv)->value : "unknown";

  Seobeo_Request_Entry *resp = NULL;
  char *body = Dowa_Arena_Allocate(arena, 256);
  snprintf(body, 256, "{\"id\":\"%s\",\"name\":\"John Doe\"}", user_id);

  Dowa_HashMap_Push_Arena(resp, "body", body, arena);
  return resp;
}


int main(void)
{
  Seobeo_Router_Init();
  Seobeo_Router_Register("GET", "/", GetHomePage);
  Seobeo_Web_Server_Start("mrjunejune/pages", "6969", SEOBEO_MODE_EDGE, 2);
}