Skip to content

Commit

Permalink
Merge pull request #556 from soehrl/feature/fix-websocket-route-macro
Browse files Browse the repository at this point in the history
Adapt CROW_WEBSOCKET_ROUTE to accept app reference
  • Loading branch information
The-EDev authored Dec 11, 2022
2 parents 3634bb7 + c1c7073 commit cae4d3e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/crow/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#else
#define CROW_ROUTE(app, url) app.template route<crow::black_magic::get_parameter_tag(url)>(url)
#define CROW_BP_ROUTE(blueprint, url) blueprint.new_rule_tagged<crow::black_magic::get_parameter_tag(url)>(url)
#define CROW_WEBSOCKET_ROUTE(app, url) app.route<crow::black_magic::get_parameter_tag(url)>(url).websocket<decltype(app)>(&app)
#define CROW_WEBSOCKET_ROUTE(app, url) app.route<crow::black_magic::get_parameter_tag(url)>(url).websocket<std::remove_reference<decltype(app)>::type>(&app)
#define CROW_MIDDLEWARES(app, ...) template middlewares<typename std::remove_reference<decltype(app)>::type, __VA_ARGS__>()
#endif
#define CROW_CATCHALL_ROUTE(app) app.catchall_route()
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions tests/external_definition/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
25 changes: 25 additions & 0 deletions tests/external_definition/main.cpp
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit cae4d3e

Please sign in to comment.