#include #include "http.h" #include "http_loop.h" #include "log.h" const char index_page[] = "\n" "\n" " \n" "

r8r.be

\n" "

This is the URL shortener and pastebin accompanying my site, The Rusty Bever.

\n" " \n" "\n"; bool lander_get_index(event_loop_conn *conn) { http_loop_ctx *ctx = conn->ctx; http_loop_res_set_body(ctx, index_page, sizeof(index_page) - 1, false); conn->state = event_loop_conn_state_res; return true; } http_route routes[] = {{.type = http_route_literal, .method = http_get, .path = "/", .steps = {lander_get_index, NULL}}}; int main() { setvbuf(stdout, NULL, _IONBF, 0); info("Initializing trie"); Trie *trie = trie_init(); int count = trie_populate(trie, "lander.data"); if (count < 0) { critical(1, "An error occured while populating the trie."); } info("Trie initialized and populated with %i entries", count); http_loop_gctx *gctx = http_loop_gctx_init(); gctx->trie = trie; gctx->routes = routes; gctx->route_count = sizeof(routes) / sizeof(routes[0]); event_loop *el = http_loop_init(gctx); event_loop_run(el, 8000); }