Add more logging
This commit is contained in:
17
routes.c
17
routes.c
@ -68,12 +68,16 @@ bool gpp_run(Allocator *alloc, char *path, NString_List *env, String_Builder *ou
|
||||
cmd_append_alloc(alloc, &cmd, env->items[i]);
|
||||
}
|
||||
|
||||
return cmd_run_collect_alloc(alloc, &cmd, out) == 0;
|
||||
bool ok = cmd_run_collect_alloc(alloc, &cmd, out) == 0;
|
||||
size_t len = out->count > 100 ? 100 : out->count;
|
||||
LOGI("Output (first 100): \n-------------------------------\n%.*s\n-------------------------------\n", len, out->items);
|
||||
return ok;
|
||||
}
|
||||
|
||||
#if MY_DEBUG
|
||||
void route_build_id(Allocator *alloc, struct mg_http_message *msg, Route_Result *result, void *context_data)
|
||||
{
|
||||
LOGI("handler build_id (%.*s)\n", msg->uri.len, msg->uri.buf);
|
||||
// TODO: Somehow use our arena in here. This will require a slight rework of the way cJSON works.
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
defer { cJSON_Delete(root); }
|
||||
@ -90,11 +94,13 @@ void route_build_id(Allocator *alloc, struct mg_http_message *msg, Route_Result
|
||||
cJSON_AddItemToObject(root, "build_id", cJSON_CreateString(sb.items));
|
||||
|
||||
make_application_json(alloc, result, 200, root);
|
||||
LOGI("handler build_id done\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
void route_page_not_found(Allocator *alloc, struct mg_http_message *msg, Route_Result *result, void *context_data)
|
||||
{
|
||||
LOGI("handler page not found (%.*s)\n", msg->uri.len, msg->uri.buf);
|
||||
NString_List env = {0};
|
||||
|
||||
list_append_alloc(alloc, &env, clonestr_alloc(alloc, fmt("-DURL=%.*s", msg->uri.len, msg->uri.buf)));
|
||||
@ -103,6 +109,7 @@ void route_page_not_found(Allocator *alloc, struct mg_http_message *msg, Route_R
|
||||
|
||||
char path[PATH_MAX] = {0};
|
||||
if (!get_baked_resource_path("page-missing.html", path, sizeof(path))) {
|
||||
LOGE("Failed to get baked resource page-missing.html\n");
|
||||
make_internal_server_error(alloc, result);
|
||||
return;
|
||||
}
|
||||
@ -126,16 +133,19 @@ void route_page_not_found(Allocator *alloc, struct mg_http_message *msg, Route_R
|
||||
} else {
|
||||
make_text(alloc, result, "html", 200, out.items);
|
||||
}
|
||||
LOGI("handler page not found done\n");
|
||||
}
|
||||
|
||||
void route_home(Allocator *alloc, struct mg_http_message *msg, Route_Result *result, void *context_data)
|
||||
{
|
||||
LOGI("handler home (%.*s)\n", msg->uri.len, msg->uri.buf);
|
||||
NString_List env = {0};
|
||||
|
||||
String_Builder out = {0};
|
||||
|
||||
char path[PATH_MAX] = {0};
|
||||
if (!get_baked_resource_path("home.html", path, sizeof(path))) {
|
||||
LOGE("Failed to get baked resource home.html\n");
|
||||
make_internal_server_error(alloc, result);
|
||||
return;
|
||||
}
|
||||
@ -159,10 +169,12 @@ void route_home(Allocator *alloc, struct mg_http_message *msg, Route_Result *res
|
||||
} else {
|
||||
make_text(alloc, result, "html", 200, out.items);
|
||||
}
|
||||
LOGI("handler home done\n");
|
||||
}
|
||||
|
||||
void route_generic_blog(Allocator *alloc, struct mg_http_message *msg, Route_Result *result, void *context_data)
|
||||
{
|
||||
LOGI("handler generic blog (%.*s)\n", msg->uri.len, msg->uri.buf);
|
||||
NString_List env = {0};
|
||||
|
||||
String_Builder out = {0};
|
||||
@ -171,6 +183,7 @@ void route_generic_blog(Allocator *alloc, struct mg_http_message *msg, Route_Res
|
||||
|
||||
char md_path[PATH_MAX] = {0};
|
||||
if (!get_baked_resource_path(resource->key, md_path, sizeof(md_path))) {
|
||||
LOGE("Failed to get baked resource %s\n", resource->key);
|
||||
make_internal_server_error(alloc, result);
|
||||
return;
|
||||
}
|
||||
@ -232,12 +245,12 @@ void route_generic_blog(Allocator *alloc, struct mg_http_message *msg, Route_Res
|
||||
} else {
|
||||
make_text(alloc, result, "html", 200, out.items);
|
||||
}
|
||||
LOGI("handler generic blog done\n");
|
||||
}
|
||||
|
||||
void collect_blogs(Baked_Resource *resource, void *udata)
|
||||
{
|
||||
struct { Allocator *alloc; String_Builder *sb; } *ud = udata;
|
||||
printf("%s\n", resource->key);
|
||||
if ((strlen(resource->key) >= strlen("blog-"))
|
||||
&& strncmp(resource->key, "blog-", strlen("blog-")) == 0) {
|
||||
sb_append_nstr_alloc(ud->alloc, ud->sb,
|
||||
|
Reference in New Issue
Block a user