Skip to content

Instantly share code, notes, and snippets.

@runexec
Created February 4, 2015 08:04
Show Gist options
  • Save runexec/bb94efad4b4eb00dbc37 to your computer and use it in GitHub Desktop.
Save runexec/bb94efad4b4eb00dbc37 to your computer and use it in GitHub Desktop.
Websocket Path Resolution in ClojureScript.
(defn current-web-port []
(as-> js/document x
(-> x .-URL str)
(or (re-find #":(\d+)/" x)
(re-find #":(\d+)" x))
(or (last x) 80)))
(defn current-domain [] (.-domain js/document))
(defn websocket-path [& [path]]
(str "ws://"
(current-domain)
":"
(current-web-port)
(or path "/ws")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment