diff --git a/backend/src/controllers/auth/auth_basic.cpp b/backend/src/controllers/auth/auth_basic.cpp index 1b0cfbb..49f9d76 100644 --- a/backend/src/controllers/auth/auth_basic.cpp +++ b/backend/src/controllers/auth/auth_basic.cpp @@ -87,7 +87,7 @@ namespace api { user_mapper.insert(new_user); generate_root(new_user); cbk(dto::Responses::get_success_res()); - } catch (const std::exception& e) { + } catch (const std::exception&) { cbk(dto::Responses::get_badreq_res("Validation error")); } } diff --git a/backend/src/main.cpp b/backend/src/main.cpp index c1186a8..d67109e 100644 --- a/backend/src/main.cpp +++ b/backend/src/main.cpp @@ -1,10 +1,13 @@ #include +#include #include #include #include "dto/dto.h" +bool dev_mode = false; + void cleanup() { std::cout << "Stopping..." << std::endl; drogon::app().quit(); @@ -14,7 +17,26 @@ void cleanup() { std::cout << "Goodbye!" << std::endl; } -int main() { +std::string get_index_content() { + std::ifstream file("./static/index.html"); + return {std::istreambuf_iterator(file), std::istreambuf_iterator()}; +} + +void default_handler(const drogon::HttpRequestPtr& req, std::function&& cbk) { + static std::string index_html = get_index_content(); + if (req->path().starts_with("/api")) { + std::cout << "Unknown api request: " << req->getMethodString() << " " << req->path() << std::endl; + cbk(drogon::HttpResponse::newNotFoundResponse()); + } else { + if (dev_mode) cbk(drogon::HttpResponse::newFileResponse("./static/index.html")); + else cbk(drogon::HttpResponse::newFileResponse((unsigned char*)index_html.data(), index_html.size())); + } +} + +int main(int argc, char* argv[]) { + std::vector args(argv+1, argv+argc); + if (std::find(args.begin(), args.end(), "--dev") != args.end()) dev_mode = true; + if (dev_mode) std::cout << "Starting in development mode" << std::endl; std::cout << "Setting up..." << std::endl; std::cout << "Initializing curl..." << std::flush; curl_global_init(CURL_GLOBAL_ALL); @@ -87,16 +109,17 @@ int main() { config["plugins"].append(access_logger); drogon::app() - .setClientMaxBodySize(1024L * 1024L * 1024L * 1024L) // 1 TB + .setClientMaxBodySize(std::numeric_limits::max()) .loadConfigJson(config) .createDbClient("sqlite3", "", 0, "", "", "", 1, "sqlite.db") - .setCustom404Page(drogon::HttpResponse::newFileResponse("./static/index.html"), false) + .setDefaultHandler(default_handler) + .setDocumentRoot("./static") .setBrStatic(true) - .setStaticFilesCacheTime(0) + .setStaticFilesCacheTime(dev_mode ? -1 : 0) .setLogPath("./logs") .setLogLevel(trantor::Logger::LogLevel::kDebug) @@ -104,7 +127,7 @@ int main() { .setIntSignalHandler(cleanup) .setTermSignalHandler(cleanup) - .addListener("0.0.0.0", 1234) + .addListener("0.0.0.0", 5678) .setThreadNum(2); std::cout << "Setup done!" << std::endl;