From cec165e29ad336d618d91fcbc087e57a2302ad42 Mon Sep 17 00:00:00 2001 From: Simon Oehrl Date: Wed, 2 Nov 2022 22:38:12 +0100 Subject: [PATCH 1/4] Adapt CROW_WEBSOCKET_ROUTE to accept app reference --- include/crow/app.h | 2 +- tests/CMakeLists.txt | 1 + tests/external_definition/CMakeLists.txt | 16 ++++++++++++++++ tests/external_definition/main.cpp | 23 +++++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/external_definition/CMakeLists.txt create mode 100644 tests/external_definition/main.cpp diff --git a/include/crow/app.h b/include/crow/app.h index 1c9d601c8..e1d07c342 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -30,7 +30,7 @@ #else #define CROW_ROUTE(app, url) app.template route(url) #define CROW_BP_ROUTE(blueprint, url) blueprint.new_rule_tagged(url) -#define CROW_WEBSOCKET_ROUTE(app, url) app.route(url).websocket(&app) +#define CROW_WEBSOCKET_ROUTE(app, url) app.route(url).websocket::type>(&app) #define CROW_MIDDLEWARES(app, ...) template middlewares::type, __VA_ARGS__>() #endif #define CROW_CATCHALL_ROUTE(app) app.catchall_route() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 07f989b50..b895a79a6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,6 +18,7 @@ endif() add_subdirectory(template) add_subdirectory(multi_file) +add_subdirectory(external_definition) if ("ssl" IN_LIST CROW_FEATURES) add_subdirectory(ssl) endif() diff --git a/tests/external_definition/CMakeLists.txt b/tests/external_definition/CMakeLists.txt new file mode 100644 index 000000000..677501df5 --- /dev/null +++ b/tests/external_definition/CMakeLists.txt @@ -0,0 +1,16 @@ +project(test_external_definition) + +add_executable( + ${PROJECT_NAME} + main.cpp +) + +target_include_directories( + ${PROJECT_NAME} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_link_libraries( + ${PROJECT_NAME} + PUBLIC Crow::Crow +) diff --git a/tests/external_definition/main.cpp b/tests/external_definition/main.cpp new file mode 100644 index 000000000..3da2f304b --- /dev/null +++ b/tests/external_definition/main.cpp @@ -0,0 +1,23 @@ +// Testing whether crow routes can be defined in an external function. +#include "crow.h" + +void define_endpoints(crow::SimpleApp& app) { + CROW_ROUTE(app, "/") ([]() { + return "Hello, world!"; + }); + CROW_WEBSOCKET_ROUTE(app, "/ws") + .onaccept([&](const crow::request&, void**) { + return true; + }) + .onopen([](crow::websocket::connection&) {}) + .onclose([](crow::websocket::connection&, std::string_view) {}); +} + +int main() +{ + crow::SimpleApp app; + + define_endpoints(app); + + app.port(18080).run(); +} From 8b34504741f8f85fbb7ac1c1986704fde8712476 Mon Sep 17 00:00:00 2001 From: Simon Oehrl Date: Sat, 5 Nov 2022 00:53:32 +0100 Subject: [PATCH 2/4] Use const string reference instead of string_view --- tests/external_definition/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/external_definition/main.cpp b/tests/external_definition/main.cpp index 3da2f304b..551374f82 100644 --- a/tests/external_definition/main.cpp +++ b/tests/external_definition/main.cpp @@ -10,7 +10,7 @@ void define_endpoints(crow::SimpleApp& app) { return true; }) .onopen([](crow::websocket::connection&) {}) - .onclose([](crow::websocket::connection&, std::string_view) {}); + .onclose([](crow::websocket::connection&, const std::string&) {}); } int main() From d0929ae66dd9568b198f7315234c39f20020b312 Mon Sep 17 00:00:00 2001 From: Simon Oehrl Date: Mon, 7 Nov 2022 13:45:59 +0100 Subject: [PATCH 3/4] Fix formatting --- tests/external_definition/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/external_definition/main.cpp b/tests/external_definition/main.cpp index 551374f82..2fa660233 100644 --- a/tests/external_definition/main.cpp +++ b/tests/external_definition/main.cpp @@ -1,8 +1,10 @@ // Testing whether crow routes can be defined in an external function. #include "crow.h" -void define_endpoints(crow::SimpleApp& app) { - CROW_ROUTE(app, "/") ([]() { +void define_endpoints(crow::SimpleApp& app) +{ + CROW_ROUTE(app, "/") + ([]() { return "Hello, world!"; }); CROW_WEBSOCKET_ROUTE(app, "/ws") From c8e376cfa54f4b01db577e7553f59c918edc2610 Mon Sep 17 00:00:00 2001 From: Andrea Cocito <39852324+puffetto@users.noreply.github.com> Date: Mon, 12 Dec 2022 21:06:42 +0100 Subject: [PATCH 4/4] Apply workaround for Apple to FreeBSD aswell Maybe these should be triggered by __clang__? --- include/crow/json.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/crow/json.h b/include/crow/json.h index 493897ee6..13706415f 100644 --- a/include/crow/json.h +++ b/include/crow/json.h @@ -1653,7 +1653,7 @@ namespace crow } else { -#if defined(__APPLE__) || defined(__MACH__) +#if defined(__APPLE__) || defined(__MACH__) || defined (__FreeBSD__) o = std::unique_ptr(new object(initializer_list)); #else (*o) = initializer_list; @@ -1672,7 +1672,7 @@ namespace crow } else { -#if defined(__APPLE__) || defined(__MACH__) +#if defined(__APPLE__) || defined(__MACH__) || defined (__FreeBSD__) o = std::unique_ptr(new object(value)); #else (*o) = value;