added favicon

This commit is contained in:
2026-02-17 17:48:37 +01:00
parent 58d37b51b7
commit d758bbd62c
17 changed files with 56 additions and 55 deletions

View File

@@ -1,18 +1,24 @@
#include <crow.h>
#include "crow/middlewares/cors.h"
#include <string>
#include "json_settings.h"
#include "utils.hpp"
#include "cors.h"
#include "login.hpp"
#include "ShadowrunApi.hpp"
#include "databasepool.h"
using namespace std;
AppSettings::Settings settings = AppSettings::load();
int main() {
crow::App<CORS> app;
AppSettings::Settings settings = AppSettings::load();
crow::App<crow::CORSHandler> app;
// init cors
auto& cors = app.get_middleware<crow::CORSHandler>();
cors.global()
.headers("Content-Type", "Authorization")
.methods("GET"_method, "POST"_method, "PUT"_method, "DELETE"_method, "OPTIONS"_method)
.origin(settings.domain);
// create global database
dbpool = std::make_unique<DatabasePool>(settings.db_path);
@@ -33,10 +39,25 @@ int main() {
return 1;
}
// options path
CROW_ROUTE(app, "/<path>") .methods("OPTIONS"_method)
([&settings](const crow::request&, crow::response& res, const std::string&) {
res.add_header("Access-Control-Allow-Origin", settings.domain);
res.add_header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
res.add_header("Access-Control-Allow-Headers", "Content-Type, Authorization");
res.add_header("Access-Control-Max-Age", "86400"); // Cache preflight for 24h
res.code = 204;
res.end();
});
// Root route
CROW_ROUTE(app, "/")([&]() {
auto data = utils::read_file(utils::build_dir / "index.html");
return crow::response(200, "text/html", data);
return utils::getFile(utils::build_dir / "index.html");
});
CROW_ROUTE(app, "/favicon.ico").methods(crow::HTTPMethod::Get)
([&]() {
return utils::getFile(utils::assets_dir / "favicon.ico");
});
shadowrun::initApi(app);
@@ -45,8 +66,7 @@ int main() {
// asssets is not svelte generated
CROW_ROUTE(app, "/assets/<path>")
([&](const std::string& p) {
const filesystem::path assets_dir = "assets/"; // <-- set your build folder
filesystem::path file_path = assets_dir / p;
filesystem::path file_path = utils::assets_dir / p;
return utils::getFile(file_path);
});