aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJaeseung Ha <ipknhama@gmail.com>2017-09-17 18:01:57 +0900
committerGitHub <noreply@github.com>2017-09-17 18:01:57 +0900
commitef17b8cb9b79921805f13f4947dadb07763ac475 (patch)
tree1f9c4ffe0dc004dc4cb648b2b58ac99c8b0dca79 /examples
parentc63113f8250c3ef0eb4dfc25aeab7e2e7c475fc4 (diff)
parentc43c052112cd15ac8be1d0cb90b6ad2570b2b99a (diff)
downloadcrow-ef17b8cb9b79921805f13f4947dadb07763ac475.tar.gz
crow-ef17b8cb9b79921805f13f4947dadb07763ac475.zip
Merge branch 'master' into master
Diffstat (limited to 'examples')
-rw-r--r--examples/example.cpp9
-rw-r--r--examples/websocket/example_ws.cpp7
-rw-r--r--examples/websocket/templates/ws.html2
3 files changed, 16 insertions, 2 deletions
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..e3c1b85 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..5200b8b 100644
--- a/examples/websocket/templates/ws.html
+++ b/examples/websocket/templates/ws.html
@@ -11,7 +11,7 @@
<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')
}