Skip to content

Commit

Permalink
clean up websocket routing
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Feb 2, 2012
1 parent 87f2ea5 commit 91e2367
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -30,13 +30,13 @@ server.set 'production'
server.listen 8080
console.log "Server started!"

server.socket.route '/', (socket) ->
server.route '/', (socket) ->
console.log "Client connected"
socket.on 'close', -> console.log "Client disconnected"
socket.on 'message', (message) ->
socket.send 'ay yo waz gud wurld'

server.socket.route '/hello', (socket) ->
server.route '/hello', (socket) ->
socket.on 'message', (message) ->
socket.send 'hello world!'
```
Expand Down
6 changes: 2 additions & 4 deletions examples/basic-server.coffee
Expand Up @@ -13,15 +13,13 @@ server.listen 8080
console.log "Server started!"

# wscat -c ws://localhost:8080/
server.socket.route '/', (socket) ->
server.route '/', (socket) ->
console.log "Client connected"
socket.on 'close', -> console.log "Client disconnected"
socket.on 'message', (message) ->
socket.send 'ay yo waz gud wurld'

# wscat -c ws://localhost:8080/helloworld/
server.socket.route '/hello', (socket) ->
console.log "Client connected"
socket.on 'close', -> console.log "Client disconnected"
server.route '/hello', (socket) ->
socket.on 'message', (message) ->
socket.send 'hello world!'
5 changes: 5 additions & 0 deletions lib/Slate.coffee
Expand Up @@ -11,12 +11,17 @@ class Slate extends EventEmitter
@socket = new SocketServer @config

# Convenience
## HTTP
root: (dir) -> @set 'root', normalize dir
engine: (args...) -> @http.engine args...
use: (args...) -> @http.use args...
enable: (args...) -> @http.enable args...
disable: (args...) -> @http.disable args...

## Sockets
route: (args...) -> @socket.route args...

## Config
set: (args...) -> @config.set args...
get: (args...) -> @config.get args...

Expand Down

0 comments on commit 91e2367

Please sign in to comment.