aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJaeseung Ha <ipknhama@gmail.com>2017-09-17 19:14:40 +0900
committerGitHub <noreply@github.com>2017-09-17 19:14:40 +0900
commit4394142d3f0c061b2a1a09b00ca6a7d12da31ddd (patch)
tree62c34a98f5f21ace43331f34e0ef7b4fa885f578 /examples
parent5921ccd0ed20a6be58e358a6fc5c89a7acc099e6 (diff)
parent4786dac0a8e908345e25a4c79da9175201f6b7fc (diff)
downloadcrow-4394142d3f0c061b2a1a09b00ca6a7d12da31ddd.tar.gz
crow-4394142d3f0c061b2a1a09b00ca6a7d12da31ddd.zip
Merge branch 'master' into fix_libssl_example
Diffstat (limited to 'examples')
-rw-r--r--examples/example.cpp9
-rw-r--r--examples/websocket/example_ws.cpp9
-rw-r--r--examples/websocket/templates/ws.html3
3 files changed, 18 insertions, 3 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 0bd2022..173d062 100644
--- a/examples/websocket/example_ws.cpp
+++ b/examples/websocket/example_ws.cpp
@@ -6,7 +6,6 @@
int main()
{
crow::SimpleApp app;
- crow::mustache::set_base(".");
std::mutex mtx;;
std::unordered_set<crow::websocket::connection*> users;
@@ -34,7 +33,13 @@ int main()
CROW_ROUTE(app, "/")
([]{
- return crow::mustache::load("ws.html").render();
+ char name[256];
+ gethostname(name, 256);
+ crow::mustache::context x;
+ x["servername"] = name;
+
+ auto page = crow::mustache::load("ws.html");
+ return page.render(x);
});
app.port(40080)
diff --git a/examples/websocket/templates/ws.html b/examples/websocket/templates/ws.html
index 5320113..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://localhost:40080/ws");
+var sock = new WebSocket("ws://{{servername}}:40080/ws");
+
sock.onopen = ()=>{
console.log('open')
}