added favicon
This commit is contained in:
12
.vscode/tasks.json
vendored
12
.vscode/tasks.json
vendored
@@ -4,7 +4,7 @@
|
|||||||
{
|
{
|
||||||
"label": "build",
|
"label": "build",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "cmake -S . -B build && cmake --build build",
|
"command": "cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON && cmake --build build && cp build/compile_commands.json compile_commands.json",
|
||||||
"group": "build",
|
"group": "build",
|
||||||
"problemMatcher": [
|
"problemMatcher": [
|
||||||
"$gcc"
|
"$gcc"
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
{
|
{
|
||||||
"label": "build release",
|
"label": "build release",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build",
|
"command": "cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON && cmake --build build && cp build/compile_commands.json compile_commands.json ",
|
||||||
"group": "build",
|
"group": "build",
|
||||||
"problemMatcher": [
|
"problemMatcher": [
|
||||||
"$gcc"
|
"$gcc"
|
||||||
@@ -26,6 +26,12 @@
|
|||||||
"options": {
|
"options": {
|
||||||
"cwd": "frontend"
|
"cwd": "frontend"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"label": "clean",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "rm -rf build/*",
|
||||||
|
"group": "build",
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ endif()
|
|||||||
file(GLOB_RECURSE ASSETS_FILES "${CMAKE_SOURCE_DIR}/assets/*")
|
file(GLOB_RECURSE ASSETS_FILES "${CMAKE_SOURCE_DIR}/assets/*")
|
||||||
file(GLOB_RECURSE FRONTEND_FILES "${CMAKE_SOURCE_DIR}/frontend/build/*")
|
file(GLOB_RECURSE FRONTEND_FILES "${CMAKE_SOURCE_DIR}/frontend/build/*")
|
||||||
|
|
||||||
foreach(file IN LISTS STATIC_FILES)
|
foreach(file IN LISTS ASSETS_FILES)
|
||||||
file(RELATIVE_PATH rel_path "${CMAKE_SOURCE_DIR}" "${file}")
|
file(RELATIVE_PATH rel_path "${CMAKE_SOURCE_DIR}" "${file}")
|
||||||
configure_file("${file}" "${CMAKE_BINARY_DIR}/${rel_path}" COPYONLY)
|
configure_file("${file}" "${CMAKE_BINARY_DIR}/${rel_path}" COPYONLY)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|||||||
BIN
assets/favicon.ico
Normal file
BIN
assets/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 977 B |
BIN
assets/favicon.png
Normal file
BIN
assets/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.1 KiB |
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"http_port" : 3010,
|
"http_port" : 3010,
|
||||||
"db_path": "/var/lib/shadowrun-server/shadowrun.db",
|
"db_path": "shadowrun.db",
|
||||||
"url": "*"
|
"domain": "*"
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
<body data-sveltekit-preload-data="hover">
|
<body data-sveltekit-preload-data="hover">
|
||||||
|
|||||||
BIN
frontend/static/favicon.ico
Normal file
BIN
frontend/static/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 977 B |
@@ -1,29 +0,0 @@
|
|||||||
#ifndef __CORS_H__
|
|
||||||
#define __CORS_H__
|
|
||||||
|
|
||||||
#include "crow.h"
|
|
||||||
#include "json_settings.h"
|
|
||||||
|
|
||||||
extern AppSettings::Settings settings;
|
|
||||||
|
|
||||||
struct CORS {
|
|
||||||
// required inner type for Crow middleware
|
|
||||||
struct context {};
|
|
||||||
|
|
||||||
void before_handle(crow::request& req, crow::response& res, context& /*ctx*/) {
|
|
||||||
// allow all origins (for dev); replace "*" with your frontend URL in production
|
|
||||||
res.add_header("Access-Control-Allow-Origin", settings.url);
|
|
||||||
res.add_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
|
|
||||||
res.add_header("Access-Control-Allow-Headers", "Content-Type");
|
|
||||||
|
|
||||||
// automatically handle preflight
|
|
||||||
if (req.method == crow::HTTPMethod::OPTIONS) {
|
|
||||||
res.end(); // stop here — no routing needed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// run after handler (not needed for CORS, but must be present)
|
|
||||||
void after_handle(crow::request&, crow::response&, context&) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // __CORS_H__
|
|
||||||
@@ -12,7 +12,7 @@ Settings AppSettings::deafult(){
|
|||||||
return Settings {
|
return Settings {
|
||||||
.http_port = 3010,
|
.http_port = 3010,
|
||||||
.db_path = "/var/lib/shadowrun-server/shadowrun.db",
|
.db_path = "/var/lib/shadowrun-server/shadowrun.db",
|
||||||
.url = "*"
|
.domain = "*"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ static constexpr char settingsFile[] = "assets/settings.json";
|
|||||||
struct Settings {
|
struct Settings {
|
||||||
int http_port;
|
int http_port;
|
||||||
std::string db_path;
|
std::string db_path;
|
||||||
std::string url;
|
std::string domain;
|
||||||
};
|
};
|
||||||
|
|
||||||
Settings load();
|
Settings load();
|
||||||
Settings deafult();
|
Settings deafult();
|
||||||
|
|
||||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Settings, http_port, db_path, url);
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Settings, http_port, db_path, domain);
|
||||||
}
|
}
|
||||||
#endif // JSON_SETTINGS_H
|
#endif // JSON_SETTINGS_H
|
||||||
@@ -45,8 +45,7 @@ std::optional<std::string> loginUser(const std::string& username, const std::str
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void initLogin(crow::App<CORS>& app)
|
void initLogin(crow::App<crow::CORSHandler>& app){
|
||||||
{
|
|
||||||
|
|
||||||
createUser("lukas", "Trollar4928");
|
createUser("lukas", "Trollar4928");
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <crow.h>
|
#include <crow.h>
|
||||||
#include "cors.h"
|
#include "crow/middlewares/cors.h"
|
||||||
|
|
||||||
namespace login {
|
namespace login {
|
||||||
|
|
||||||
void initLogin(crow::App<CORS>& app);
|
void initLogin(crow::App<crow::CORSHandler>& app);
|
||||||
|
|
||||||
std::optional<crow::response> isLoggedIn(const crow::request& req);
|
std::optional<crow::response> isLoggedIn(const crow::request& req);
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,24 @@
|
|||||||
#include <crow.h>
|
#include <crow.h>
|
||||||
|
#include "crow/middlewares/cors.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "json_settings.h"
|
#include "json_settings.h"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
#include "cors.h"
|
|
||||||
#include "login.hpp"
|
#include "login.hpp"
|
||||||
#include "ShadowrunApi.hpp"
|
#include "ShadowrunApi.hpp"
|
||||||
#include "databasepool.h"
|
#include "databasepool.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
AppSettings::Settings settings = AppSettings::load();
|
|
||||||
|
|
||||||
int main() {
|
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
|
// create global database
|
||||||
dbpool = std::make_unique<DatabasePool>(settings.db_path);
|
dbpool = std::make_unique<DatabasePool>(settings.db_path);
|
||||||
@@ -33,10 +39,25 @@ int main() {
|
|||||||
return 1;
|
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
|
// Root route
|
||||||
CROW_ROUTE(app, "/")([&]() {
|
CROW_ROUTE(app, "/")([&]() {
|
||||||
auto data = utils::read_file(utils::build_dir / "index.html");
|
return utils::getFile(utils::build_dir / "index.html");
|
||||||
return crow::response(200, "text/html", data);
|
});
|
||||||
|
|
||||||
|
CROW_ROUTE(app, "/favicon.ico").methods(crow::HTTPMethod::Get)
|
||||||
|
([&]() {
|
||||||
|
return utils::getFile(utils::assets_dir / "favicon.ico");
|
||||||
});
|
});
|
||||||
|
|
||||||
shadowrun::initApi(app);
|
shadowrun::initApi(app);
|
||||||
@@ -45,8 +66,7 @@ int main() {
|
|||||||
// asssets is not svelte generated
|
// asssets is not svelte generated
|
||||||
CROW_ROUTE(app, "/assets/<path>")
|
CROW_ROUTE(app, "/assets/<path>")
|
||||||
([&](const std::string& p) {
|
([&](const std::string& p) {
|
||||||
const filesystem::path assets_dir = "assets/"; // <-- set your build folder
|
filesystem::path file_path = utils::assets_dir / p;
|
||||||
filesystem::path file_path = assets_dir / p;
|
|
||||||
return utils::getFile(file_path);
|
return utils::getFile(file_path);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ static std::unordered_map<std::string, std::string> parse_query_string(const std
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initApi(crow::App<CORS>& app){
|
void initApi(crow::App<crow::CORSHandler>& app){
|
||||||
|
|
||||||
CROW_ROUTE(app, "/assets/shadowrun/<path>")
|
CROW_ROUTE(app, "/assets/shadowrun/<path>")
|
||||||
([&](const crow::request& req, const std::string& p) {
|
([&](const crow::request& req, const std::string& p) {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#ifndef __SHADOWRUNAPI_H__
|
#ifndef __SHADOWRUNAPI_H__
|
||||||
#define __SHADOWRUNAPI_H__
|
#define __SHADOWRUNAPI_H__
|
||||||
|
|
||||||
#include "cors.h"
|
#include "crow.h"
|
||||||
#include <crow.h>
|
#include "crow/middlewares/cors.h"
|
||||||
|
|
||||||
namespace shadowrun {
|
namespace shadowrun {
|
||||||
|
|
||||||
void initApi(crow::App<CORS>& app);
|
void initApi(crow::App<crow::CORSHandler>& app);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif // __SHADOWRUNAPI_H__
|
#endif // __SHADOWRUNAPI_H__
|
||||||
@@ -164,6 +164,7 @@ std::string get_mime_type(const std::string& path) {
|
|||||||
if (path.ends_with(".woff")) return "font/woff";
|
if (path.ends_with(".woff")) return "font/woff";
|
||||||
if (path.ends_with(".woff2")) return "font/woff2";
|
if (path.ends_with(".woff2")) return "font/woff2";
|
||||||
if (path.ends_with(".pdf")) return "application/pdf";
|
if (path.ends_with(".pdf")) return "application/pdf";
|
||||||
|
if (path.ends_with(".ico")) return "image/x-icon";
|
||||||
return "application/octet-stream";
|
return "application/octet-stream";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,10 @@
|
|||||||
#include "crow.h"
|
#include "crow.h"
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
const std::filesystem::path build_dir = "frontend/build/"; // <-- set your build folder
|
// Svelte genereated files
|
||||||
|
const std::filesystem::path build_dir = "frontend/build/";
|
||||||
|
// Non-autogenerated assets folder
|
||||||
|
const std::filesystem::path assets_dir = "assets/";
|
||||||
|
|
||||||
std::map<std::string, std::string> parseBody(const std::string& body);
|
std::map<std::string, std::string> parseBody(const std::string& body);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user