first release 0.1.1
This commit is contained in:
@@ -41,6 +41,12 @@ expected<AppSettings, string> AppSettings::loadAppSettings() {
|
||||
return unexpected("'services' array in JSON file is empty");
|
||||
}
|
||||
|
||||
if (j.contains("httpPort")) {
|
||||
settings.httpPort = j["httpPort"].get<int>();
|
||||
} else {
|
||||
settings.httpPort = {};
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <string>
|
||||
#include <expected>
|
||||
#include <optional>
|
||||
#include <cstdint>
|
||||
|
||||
struct Service {
|
||||
std::string name;
|
||||
@@ -17,6 +18,7 @@ struct AppSettings {
|
||||
std::optional<std::string> getId(std::string_view name);
|
||||
|
||||
std::vector<Service> services;
|
||||
std::optional<uint16_t> httpPort;
|
||||
};
|
||||
|
||||
#endif // JSON_SETTINGS_H
|
||||
17
src/main.cpp
17
src/main.cpp
@@ -3,6 +3,7 @@
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <print>
|
||||
#include <optional>
|
||||
#include "json_settings.h"
|
||||
#include "htmx_helper.h"
|
||||
@@ -68,5 +69,19 @@ int main() {
|
||||
return crow::response{row.htmx()};
|
||||
});
|
||||
|
||||
app.port(8080).multithreaded().run();
|
||||
const uint16_t defaultPort = 3010;
|
||||
uint16_t httpPort = defaultPort;
|
||||
|
||||
{
|
||||
auto opt_settings = AppSettings::loadAppSettings();
|
||||
if (opt_settings.has_value()){
|
||||
auto& settings = opt_settings.value();
|
||||
httpPort = settings.httpPort.value_or(defaultPort);
|
||||
} else {
|
||||
CROW_LOG_ERROR << "failed to load settings : " << opt_settings.error();
|
||||
}
|
||||
}
|
||||
|
||||
app.loglevel(crow::LogLevel::INFO);
|
||||
app.port(httpPort).multithreaded().run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user