Merge pull request #226 from jcoffin01/fix_url

Modified websocket example to automatically retrieve server's hostname.
This commit is contained in:
Jaeseung Ha 2017-09-06 15:42:53 +09:00 committed by GitHub
commit 51d51bac9b
2 changed files with 7 additions and 2 deletions

View File

@ -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)

View File

@ -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')
}