-
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt CROW_WEBSOCKET_ROUTE to accept app reference
- Loading branch information
Showing
4 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |