Merge pull request #177 from tekn0ir/fix_libssl_example

Fix linking error on OSX & fix websocket example
This commit is contained in:
Jaeseung Ha 2017-09-17 19:15:03 +09:00 committed by GitHub
commit 6df366ce1d
3 changed files with 12 additions and 5 deletions

View File

@ -19,7 +19,13 @@ endif()
add_executable(example_websocket websocket/example_ws.cpp) add_executable(example_websocket websocket/example_ws.cpp)
target_link_libraries(example_websocket ${Boost_LIBRARIES}) 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
)
add_custom_target(example_ws_copy ALL DEPENDS ws.html)
add_executable(example example.cpp) add_executable(example example.cpp)
#target_link_libraries(example crow) #target_link_libraries(example crow)

View File

@ -33,10 +33,10 @@ int main()
CROW_ROUTE(app, "/") CROW_ROUTE(app, "/")
([]{ ([]{
char name[256]; char name[256];
gethostname(name, 256); gethostname(name, 256);
crow::mustache::context x; crow::mustache::context x;
x["servername"] = name; x["servername"] = name;
auto page = crow::mustache::load("ws.html"); auto page = crow::mustache::load("ws.html");
return page.render(x); return page.render(x);

View File

@ -12,6 +12,7 @@
</textarea> </textarea>
<script> <script>
var sock = new WebSocket("ws://{{servername}}:40080/ws"); var sock = new WebSocket("ws://{{servername}}:40080/ws");
sock.onopen = ()=>{ sock.onopen = ()=>{
console.log('open') console.log('open')
} }