layout source from main

This commit is contained in:
2026-06-13 10:49:41 +07:00
parent 8c111f2406
commit 853acefac1
25 changed files with 1848 additions and 1463 deletions

41
src/util/http_util.cpp Normal file
View File

@@ -0,0 +1,41 @@
#include "util/http_util.hpp"
#include "util/string_util.hpp"
namespace lm {
std::string HttpUtil::contentTypeForPath(const std::filesystem::path& p)
{
const auto ext = StringUtil::toLower(p.extension().string());
if (ext == ".html")
return "text/html; charset=utf-8";
if (ext == ".css")
return "text/css; charset=utf-8";
if (ext == ".js")
return "application/javascript; charset=utf-8";
if (ext == ".json")
return "application/json; charset=utf-8";
if (ext == ".png")
return "image/png";
if (ext == ".svg")
return "image/svg+xml";
if (ext == ".ico")
return "image/x-icon";
return "application/octet-stream";
}
void HttpUtil::jsonError(httplib::Response& res, int status, const std::string& msg)
{
res.status = status;
res.set_header("Content-Type", "application/json; charset=utf-8");
res.body = nlohmann::json({{"error", msg}}).dump();
}
void HttpUtil::addCors(httplib::Response& res)
{
res.set_header("Access-Control-Allow-Origin", "*");
res.set_header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
res.set_header("Access-Control-Allow-Headers", "Content-Type");
}
} // namespace lm