documentation server and /doc route

Signed-off-by: ngn <ngn@ngn.tf>
This commit is contained in:
ngn
2025-01-16 07:46:27 +03:00
parent 5fb3c03e40
commit e87764a4c2
40 changed files with 1313 additions and 301 deletions

View File

@ -1,25 +1,41 @@
#include <ctorm/all.h>
#include <ctorm/ctorm.h>
#include <stdlib.h>
#include "routes.h"
#include "config.h"
#include "routes.h"
int main() {
config_t conf;
app_config_t config;
ctorm_app_t *app = NULL;
ctorm_config_t app_config;
if (config_load(&conf) < 0)
config_t conf;
char *host = NULL;
if (!config_load(&conf))
return EXIT_FAILURE;
host = config_get(&conf, "host");
app_config_new(&config);
config.disable_logging = true;
ctorm_config_new(&app_config);
app_config.disable_logging = true;
app = ctorm_app_new(&app_config);
app_t *app = app_new(&config);
GET(app, "/read", GET_read);
// middlewares
MIDDLEWARE_ALL(app, "/*", route_cors);
MIDDLEWARE_ALL(app, "/*/*", route_cors);
MIDDLEWARE_ALL(app, "/*/*/*", route_cors);
if (!app_run(app, config_get(&conf, "host")))
error("failed to start the app: %s", app_geterror());
// routes
GET(app, "/list", route_list);
GET(app, "/get/:name", route_get);
app_free(app);
ctorm_app_all(app, route_notfound);
ctorm_app_local(app, "config", &conf);
ctorm_info("starting the web server on %s", host);
if (!ctorm_app_run(app, host))
ctorm_fail("failed to start the app: %s", ctorm_geterror());
ctorm_app_free(app);
return EXIT_SUCCESS;
}