aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJaeseung Ha <ipknhama@gmail.com>2017-09-18 00:43:42 +0900
committerGitHub <noreply@github.com>2017-09-18 00:43:42 +0900
commit08acc7c0bedc24bf5b8c6cc01f1701b0d45e141e (patch)
tree77aa4aa0f2cbfd139dc3194a3cf113ed2100454f /examples
parente40605da59e368be524dee0e9e9d41ef05149473 (diff)
parent194a9ef6812e3d5476419e33be2756ab69fc0696 (diff)
downloadcrow-08acc7c0bedc24bf5b8c6cc01f1701b0d45e141e.tar.gz
crow-08acc7c0bedc24bf5b8c6cc01f1701b0d45e141e.zip
Merge branch 'master' into master
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt8
-rw-r--r--examples/example.cpp9
-rw-r--r--examples/websocket/example_ws.cpp7
-rw-r--r--examples/websocket/templates/ws.html3
4 files changed, 21 insertions, 6 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index ee9bd0c..b92539e 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -18,11 +18,11 @@ endif()
add_executable(example_websocket websocket/example_ws.cpp)
target_link_libraries(example_websocket ${Boost_LIBRARIES})
-target_link_libraries(example_websocket ${CMAKE_THREAD_LIBS_INIT} ssl crypto)
+target_link_libraries(example_websocket ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES})
add_custom_command(OUTPUT ws.html
- COMMAND ${CMAKE_COMMAND} -E
- copy ${PROJECT_SOURCE_DIR}/websocket/templates/ws.html ${CMAKE_CURRENT_BINARY_DIR}/ws.html
- DEPENDS ${PROJECT_SOURCE_DIR}/websocket/templates/ws.html
+ COMMAND ${CMAKE_COMMAND} -E
+ copy ${PROJECT_SOURCE_DIR}/websocket/templates/ws.html ${CMAKE_CURRENT_BINARY_DIR}/templates/ws.html
+ DEPENDS ${PROJECT_SOURCE_DIR}/websocket/templates/ws.html
)
add_custom_target(example_ws_copy ALL DEPENDS ws.html)
diff --git a/examples/example.cpp b/examples/example.cpp
index b4cbe40..87231a2 100644
--- a/examples/example.cpp
+++ b/examples/example.cpp
@@ -146,6 +146,15 @@ int main()
for(const auto& countVal : count) {
os << " - " << countVal << '\n';
}
+
+ // To get a dictionary from the request
+ // You have to submit something like '/params?mydict[a]=b&mydict[abcd]=42' to have a list of pairs ((a, b) and (abcd, 42))
+ auto mydict = req.url_params.get_dict("mydict");
+ os << "The key 'dict' contains " << mydict.size() << " value(s).\n";
+ for(const auto& mydictVal : mydict) {
+ os << " - " << mydictVal.first << " -> " << mydictVal.second << '\n';
+ }
+
return crow::response{os.str()};
});
diff --git a/examples/websocket/example_ws.cpp b/examples/websocket/example_ws.cpp
index ec3603c..173d062 100644
--- a/examples/websocket/example_ws.cpp
+++ b/examples/websocket/example_ws.cpp
@@ -33,8 +33,13 @@ int main()
CROW_ROUTE(app, "/")
([]{
+ char name[256];
+ gethostname(name, 256);
+ crow::mustache::context x;
+ x["servername"] = name;
+
auto page = crow::mustache::load("ws.html");
- return page.render();
+ return page.render(x);
});
app.port(40080)
diff --git a/examples/websocket/templates/ws.html b/examples/websocket/templates/ws.html
index f6e7281..2d38fdf 100644
--- a/examples/websocket/templates/ws.html
+++ b/examples/websocket/templates/ws.html
@@ -11,7 +11,8 @@
<textarea id="log" cols=100 rows=50>
</textarea>
<script>
-var sock = new WebSocket("ws://i.ipkn.me:40080/ws");
+var sock = new WebSocket("ws://{{servername}}:40080/ws");
+
sock.onopen = ()=>{
console.log('open')
}