added version number to build
This commit is contained in:
@@ -87,8 +87,13 @@ target_link_options(${TARGET_NAME} PRIVATE
|
||||
$<$<CONFIG:Release>:-flto=auto>
|
||||
)
|
||||
|
||||
if(NOT DEFINED APP_VERSION)
|
||||
set(APP_VERSION "0.0.0")
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE
|
||||
APPLICATION_NAME="${TARGET_NAME}"
|
||||
APP_VERSION="${APP_VERSION}"
|
||||
SQLITE_THREADSAFE=1 # build sqlite with thread safty
|
||||
ASIO_STANDALONE # use asio without boost
|
||||
CROW_ENABLE_COMPRESSION # enable compression part of crow
|
||||
|
||||
5
PKGBUILD
5
PKGBUILD
@@ -1,7 +1,7 @@
|
||||
# Maintainer: Lukas Forsberg lukas96.forsberg@gmail.com
|
||||
|
||||
pkgname=shadowrun-server
|
||||
pkgver=0.1.3
|
||||
pkgver=0.1.4
|
||||
pkgrel=1
|
||||
arch=('x86_64')
|
||||
depends=()
|
||||
@@ -18,7 +18,8 @@ build() {
|
||||
cmake -S "${srcdir}" \
|
||||
-B build \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_PREFIX=/usr
|
||||
-DCMAKE_INSTALL_PREFIX=/usr \
|
||||
-DAPP_VERSION=${pkgver}
|
||||
|
||||
cmake --build build
|
||||
}
|
||||
|
||||
26
source/Application.hpp
Normal file
26
source/Application.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef __APPVERSION_H__
|
||||
#define __APPVERSION_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Application {
|
||||
|
||||
#ifndef APP_VERSION
|
||||
#define APP_VERSION "0.0.0"
|
||||
#endif
|
||||
|
||||
#ifndef APPLICATION_NAME
|
||||
#define APPLICATION_NAME "app"
|
||||
#endif
|
||||
|
||||
inline std::string version(){
|
||||
return std::string(APP_VERSION);
|
||||
}
|
||||
|
||||
inline std::string name(){
|
||||
return std::string(APPLICATION_NAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // __APPVERSION_H__
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <fstream>
|
||||
#include "json.hpp"
|
||||
#include "json_settings.h"
|
||||
#include "crow/logging.h"
|
||||
#include "utils.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using json = nlohmann::json;
|
||||
@@ -19,7 +19,7 @@ Settings AppSettings::deafult(){
|
||||
Settings AppSettings::load() {
|
||||
ifstream file(settingsFile);
|
||||
if (!file.is_open()) {
|
||||
CROW_LOG_ERROR << "Failed to load settings file" << settingsFile << " Loading default settings";
|
||||
std::cerr << "Failed to load settings file" << settingsFile << " Loading default settings" << std::endl;
|
||||
return AppSettings::deafult();
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@ Settings AppSettings::load() {
|
||||
auto result = utils::parseJson(fileContents);
|
||||
|
||||
if(!result){
|
||||
CROW_LOG_ERROR << "failed to parse settings file, Loading default settings";
|
||||
std::cerr << "failed to parse settings file, Loading default settings" << std::endl;
|
||||
return AppSettings::deafult();
|
||||
}
|
||||
|
||||
try {
|
||||
return result.value().get<Settings>();
|
||||
} catch (...) {
|
||||
CROW_LOG_ERROR << "failed to parse settings file, Loading default settings";
|
||||
std::cerr << "failed to parse settings file, Loading default settings";
|
||||
return AppSettings::deafult();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,18 +7,21 @@
|
||||
#include "ShadowrunApi.hpp"
|
||||
#include "databasepool.h"
|
||||
#include "crow/compression.h"
|
||||
#include "Application.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
std::cout << "Launching " << Application::name() << " version: " << Application::version() << std::endl;
|
||||
|
||||
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)
|
||||
.headers("Content-Type", "Authorization")
|
||||
.methods("GET"_method, "POST"_method, "PUT"_method, "DELETE"_method, "OPTIONS"_method)
|
||||
.allow_credentials()
|
||||
.origin(settings.domain)
|
||||
.max_age(86400);
|
||||
@@ -26,22 +29,22 @@ int main() {
|
||||
// create global database
|
||||
dbpool = std::make_unique<DatabasePool>(settings.db_path);
|
||||
if (!dbpool->init(std::thread::hardware_concurrency())){
|
||||
CROW_LOG_ERROR << "Failed to create database at : " << settings.db_path;
|
||||
return 1;
|
||||
std::cerr << "Failed to create database at : " << settings.db_path << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
auto opt_isPortOpen = utils::isLocalPortOpen(settings.http_port);
|
||||
if (opt_isPortOpen.has_value()){
|
||||
if (opt_isPortOpen.value()){
|
||||
CROW_LOG_ERROR << "Local port : " << settings.http_port << " is already open";
|
||||
return 1;
|
||||
std::cerr << "Local port : " << settings.http_port << " is already open" << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
CROW_LOG_ERROR << "failed to check if local port is open : " << opt_isPortOpen.error();
|
||||
return 1;
|
||||
std::cerr << "failed to check if local port is open : " << opt_isPortOpen.error() << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
|
||||
// Root route
|
||||
CROW_ROUTE(app, "/")([&]() {
|
||||
return utils::getFile(utils::build_dir / "index.html");
|
||||
@@ -54,14 +57,14 @@ int main() {
|
||||
|
||||
shadowrun::initApi(app);
|
||||
login::initLogin(app);
|
||||
|
||||
|
||||
// asssets is not svelte generated
|
||||
CROW_ROUTE(app, "/assets/<path>")
|
||||
([&](const std::string& p) {
|
||||
filesystem::path file_path = utils::assets_dir / p;
|
||||
return utils::getFile(file_path);
|
||||
});
|
||||
|
||||
|
||||
// Catch-all route for static files and SPA fallback
|
||||
CROW_ROUTE(app, "/<path>")
|
||||
([&](const std::string& p) {
|
||||
|
||||
Reference in New Issue
Block a user