Mercurial > sci
diff http.c @ 3:215c0c3b3609
misc: use JSON everywhere (scictl/sciwebd)
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 14 Jun 2021 22:08:24 +0200 |
parents | 5fa3d2f479b2 |
children | 3051ef92173a |
line wrap: on
line diff
--- a/http.c Thu Jun 10 10:39:21 2021 +0200 +++ b/http.c Mon Jun 14 22:08:24 2021 +0200 @@ -11,7 +11,8 @@ #include "log.h" #include "page.h" #include "page-api-jobs.h" -#include "page-api-script.h" +#include "page-api-projects.h" +#include "page-api-workers.h" #include "req.h" enum page { @@ -26,27 +27,17 @@ const char *prefix; void (*handler)(struct kreq *); } apis[] = { - { "v1/jobs", page_api_v1_jobs }, - { "v1/script", page_api_v1_script }, - { NULL, NULL } + { "v1/jobs", page_api_v1_jobs }, + { "v1/projects", page_api_v1_projects }, + { "v1/workers", page_api_v1_workers }, + { NULL, NULL } }; - if (req_connect(VARDIR "/run/sci.sock") < 0) { - page(req, NULL, KHTTP_500, KMIME_TEXT_HTML, "pages/500.html"); - return; - } - - for (size_t i = 0; apis[i].prefix; ++i) { - if (strncmp(req->path, apis[i].prefix, strlen(apis[i].prefix)) == 0) { - apis[i].handler(req); - goto finish; - } - } + for (size_t i = 0; apis[i].prefix; ++i) + if (strncmp(req->path, apis[i].prefix, strlen(apis[i].prefix)) == 0) + return apis[i].handler(req); page(req, NULL, KHTTP_404, KMIME_TEXT_HTML, "pages/404.html"); - -finish: - req_finish(); } static const char *pages[] = {