montagejs / joey

An HTTP content negotiation client and server JavaScript library, inspired by Sinatra and JSGI, and using Q promises.
Other
40 stars 7 forks source link

Integrate with express somehow #13

Open wmertens opened 9 years ago

wmertens commented 9 years ago

There is a large ExpressJS ecosystem, and there are many interesting middlewares like Passport for authentication.

I'd like to discuss the possibilities of integrating the two.

I see two possibilities:

On the face of it, the latter seems the most plausible since it means not running after Express trying to copy its API.

Does that sound plausible/am I on crack? Any tips for implementing?

Stuk commented 9 years ago

Yeah, I've thought about this idea, exactly because there's a large ecosystem of Express packages.

I briefly thought about making Express compatible request/response objects, but (as far as I can remember) there are several big compat issues, such as Joey's body streaming being very different to the built in streams.

An Express middleware that runs Joey chains sounds like an interesting idea that's worth exploring. The main thing to think about would be how the Joey response object could be translated to the Express response object.

wmertens commented 9 years ago

@Stuk I'm thinking that basically there would be a .express() instead of a .server() and it would generate Express middleware that runs the request through the chain and if the response is not undefined it res.send()s it. I suppose errors should just be sent to next().

There might be Joey apps that aren't happy about getting a pre-processed request object, like the bodyparser, but in general it should just work methinks.

Hmmm I should just try it, see if you can beat me to it :grin:.

Stuk commented 9 years ago

I'm not going to have any time to take a look soon, so please, go ahead!

On January 15, 2015 4:54:09 AM PST, wmertens notifications@github.com wrote:

@Stuk I'm thinking that basically there would be a .express() instead of a .server() and it would generate Express middleware that runs the request through the chain and if the response is not undefined it res.send()s it. I suppose errors should just be sent to next().

There might be Joey apps that aren't happy about getting a pre-processed request object, like the bodyparser, but in general it should just work methinks.

Hmmm I should just try it, see if you can beat me to it :grin:.


Reply to this email directly or view it on GitHub: https://github.com/montagejs/joey/issues/13#issuecomment-70081456

kriskowal commented 9 years ago

.express() or .connect() (from which Express gets its protocol) seems sane. Seems analogous to promise.nodeify(). Could reuse nodeify() since it might as well be the Node.js convention.