Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route Forwarding: receive multiple arguments res.io.respond(a,b,c,...) #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/route-forwarding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ app.io.route('hello-again', function(req) {
app.listen(7076)
```

__Note__: When you forward http requests to io routes, `req.io.respond(data)` will call `res.json(data)` on the actual http request. This makes sense because http routes require a response, and the `respond` method is supposed to be a response for the given request.
__Note__: When you forward http requests to io routes, `req.io.respond(err, data)` will call `res.json([err, data])` on the actual http request. This makes sense because http routes require a response, and the `respond` method is supposed to be a response for the given request.

Also, depending on the sophistication needed between a socket request and a web request, you might consider writing your own custom middleware layer and overriding `req.io.route` for your web requests.

2 changes: 1 addition & 1 deletion lib/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ express.application.io = (options) ->
broadcast: @io.broadcast
respond: =>
args = Array.prototype.slice.call arguments, 0
response.json.apply response, args
response.json.call response, args
route: (route) =>
@io.route route, ioRequest, trigger: true
data: request.body
Expand Down