#include "gebs/gebs.h" #include "mongoose/mongoose.h" #include "routes.h" #include "gpp.h" void route_page_not_found(struct mg_connection *conn, struct mg_http_message *msg) { NString_List env = {0}; defer { list_free(&env); } list_append(&env, fmt("-DURL=%.*s", msg->uri.len, msg->uri.buf)); String_Builder out = {0}; defer { sb_free(&out); } bool ok = gpp_run("./tmpls/page-missing.t", &env, &out); sb_finish(&out); if (!ok) { mg_http_reply(conn, 500, "Content-Type: text/html\r\n", "Internal server error ;("); } else { mg_http_reply(conn, 404, "Content-Type: text/html\r\n", out.items); } } void route_simple_css(struct mg_connection *conn, struct mg_http_message *msg) { struct mg_http_serve_opts opts = { 0 }; mg_http_serve_file(conn, msg, "./assets/simple.min.css", &opts); } void route_favicon(struct mg_connection *conn, struct mg_http_message *msg) { struct mg_http_serve_opts opts = { 0 }; mg_http_serve_file(conn, msg, "./assets/favicon.ico", &opts); } void route_home(struct mg_connection *conn, struct mg_http_message *msg) { NString_List env = {0}; defer { list_free(&env); } String_Builder out = {0}; defer { sb_free(&out); } bool ok = gpp_run("./tmpls/index.t", &env, &out); sb_finish(&out); if (!ok) { mg_http_reply(conn, 500, "Content-Type: text/html\r\n", "Internal server error ;("); } else { mg_http_reply(conn, 200, "Content-Type: text/html\r\n", out.items); } }