File tree Expand file tree Collapse file tree 4 files changed +41
-1
lines changed Expand file tree Collapse file tree 4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 30
30
#else
31
31
#define CROW_ROUTE (app, url ) app.template route<crow::black_magic::get_parameter_tag(url)>(url)
32
32
#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)
34
34
#define CROW_MIDDLEWARES (app, ...) template middlewares<typename std::remove_reference<decltype (app)>::type, __VA_ARGS__>()
35
35
#endif
36
36
#define CROW_CATCHALL_ROUTE (app ) app.catchall_route()
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ endif()
18
18
19
19
add_subdirectory (template )
20
20
add_subdirectory (multi_file )
21
+ add_subdirectory (external_definition )
21
22
if ("ssl" IN_LIST CROW_FEATURES )
22
23
add_subdirectory (ssl )
23
24
endif ()
Original file line number Diff line number Diff line change
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
+ )
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments