server.esl 495 B

123456789101112131415
  1. (lambda server (host port routes)
  2. (var http-server (new (. (require "http") Server)))
  3. (http-server.on "request" (lambda (req res)
  4. (./util/router (?: (instanceof routes Function) (routes) routes)
  5. req res)))
  6. (http-server.listen port)
  7. (var socket-server (new (. (require "ws") Server) (object "server" http-server)))
  8. (socket-server.on "connection" (lambda (socket) (./util/connected routes socket)))
  9. (return (object
  10. "http" http-server
  11. "sockets" socket-server)))