app.js 1.2 KB

123456789101112131415161718192021222324
  1. /*global io:true */
  2. // Shared client bootstrap: where the app is mounted, and the one socket the
  3. // page uses. Loaded before start.js and play.js, which both rely on these.
  4. //
  5. // This replaces the old ENV switch ('dev' | 'code' | 'chess'), which hardcoded
  6. // a host and port per environment and had to be hand-edited to deploy -- the
  7. // last such edit being the `ENV = 'chess'` line that came down from the server.
  8. // Mounted under /chess the app is same-origin with the rest of the site, so
  9. // there is nothing left to hardcode: io() defaults to the page's own origin,
  10. // which follows http/https on its own and so can't trip mixed-content blocking
  11. // on a TLS page the way ws://chess.davidawindham.com:8181 did.
  12. var $URL, $socket;
  13. // window.$BASE is emitted by views/layout.pug from the server's BASE_PATH.
  14. // '' when served at a domain root, '/chess' behind Apache.
  15. var $BASE = window.$BASE || '';
  16. // Absolute -- start.js builds the shareable game link out of this, so it needs
  17. // the origin, unlike the page's own assets.
  18. $URL = window.location.origin + $BASE;
  19. // Must line up with the server's socket.io path and the proxy's websocket rule.
  20. $socket = io({ path: $BASE + '/socket.io' });