Skip to content

Commit 5d43b99

Browse files
soehrlThe-EDev
authored andcommitted
Adapt CROW_WEBSOCKET_ROUTE to accept app reference
1 parent 3994bf2 commit 5d43b99

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

include/crow/app.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#else
3131
#define CROW_ROUTE(app, url) app.template route<crow::black_magic::get_parameter_tag(url)>(url)
3232
#define CROW_BP_ROUTE(blueprint, url) blueprint.new_rule_tagged<crow::black_magic::get_parameter_tag(url)>(url)
33-
#define CROW_WEBSOCKET_ROUTE(app, url) app.route<crow::black_magic::get_parameter_tag(url)>(url).websocket<decltype(app)>(&app)
33+
#define CROW_WEBSOCKET_ROUTE(app, url) app.route<crow::black_magic::get_parameter_tag(url)>(url).websocket<std::remove_reference<decltype(app)>::type>(&app)
3434
#define CROW_MIDDLEWARES(app, ...) template middlewares<typename std::remove_reference<decltype(app)>::type, __VA_ARGS__>()
3535
#endif
3636
#define CROW_CATCHALL_ROUTE(app) app.catchall_route()

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ endif()
1818

1919
add_subdirectory(template)
2020
add_subdirectory(multi_file)
21+
add_subdirectory(external_definition)
2122
if ("ssl" IN_LIST CROW_FEATURES)
2223
add_subdirectory(ssl)
2324
endif()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
project(test_external_definition)
2+
3+
add_executable(
4+
${PROJECT_NAME}
5+
main.cpp
6+
)
7+
8+
target_include_directories(
9+
${PROJECT_NAME}
10+
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
11+
)
12+
13+
target_link_libraries(
14+
${PROJECT_NAME}
15+
PUBLIC Crow::Crow
16+
)

tests/external_definition/main.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Testing whether crow routes can be defined in an external function.
2+
#include "crow.h"
3+
4+
void define_endpoints(crow::SimpleApp& app) {
5+
CROW_ROUTE(app, "/") ([]() {
6+
return "Hello, world!";
7+
});
8+
CROW_WEBSOCKET_ROUTE(app, "/ws")
9+
.onaccept([&](const crow::request&, void**) {
10+
return true;
11+
})
12+
.onopen([](crow::websocket::connection&) {})
13+
.onclose([](crow::websocket::connection&, std::string_view) {});
14+
}
15+
16+
int main()
17+
{
18+
crow::SimpleApp app;
19+
20+
define_endpoints(app);
21+
22+
app.port(18080).run();
23+
}

0 commit comments

Comments
 (0)