diff --git a/include/crow/app.h b/include/crow/app.h index 7b076b069..d76689206 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/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; 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..2fa660233 --- /dev/null +++ b/tests/external_definition/main.cpp @@ -0,0 +1,25 @@ +// 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&, const std::string&) {}); +} + +int main() +{ + crow::SimpleApp app; + + define_endpoints(app); + + app.port(18080).run(); +}