From ba048ee34e139fb09cad9a9b6c11b6da998ae68d Mon Sep 17 00:00:00 2001 From: McFog Date: Sat, 8 Mar 2014 22:46:45 +0800 Subject: [PATCH] change route-forwarding mechanism to accept `req.io.respond(null, arg1, arg2, ...)` => `res.json([null, arg1, arg2, ...])` --- examples/route-forwarding/README.md | 2 +- lib/index.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/route-forwarding/README.md b/examples/route-forwarding/README.md index 38fc8d8..fb8f2ed 100644 --- a/examples/route-forwarding/README.md +++ b/examples/route-forwarding/README.md @@ -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. diff --git a/lib/index.coffee b/lib/index.coffee index eecfe2c..37b7928 100644 --- a/lib/index.coffee +++ b/lib/index.coffee @@ -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