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

Already on GitHub? Sign in to your account

Integration with Connect server #89

ggoodman opened this Issue Mar 2, 2012 · 9 comments


None yet
8 participants

ggoodman commented Mar 2, 2012

The object created by restify.createServer() cannot be used as middleware in a connect-based server.

The reason that this would be useful would be to mount a restify server at a specific path for an existing server:

// Mount the restify server from ./servers/api.js at the path "/path/to/api"
app.use("/path/to/api", require("./servers/api"));

This approach would allow an application to benefit from connect/express specific advantages for serving templated html pages at the root while leveraging restify's REST api competencies at that specific path.

Note that I have tried the following:

// ./servers/api.js

server = restify.createServer()

// Define routes, etc..

// Export the HttpServer created by Restify for connect to mount as per above
module.exports = server.server

This approach causes connect's /lib/patch.js to spew errors that headers have already been sent (by Restify)


sberryman commented Mar 2, 2012

Excellent idea +1


mcavage commented Mar 3, 2012

Yeah, I'm sure this doesn't work :)

I'll leave this open and look into it, but I'm pretty confident it won't be trivial (i.e., this is not going to happen in a super short timeframe).


+1 on this.

I currently have a connect 2.0 based app that has manually managed rest endpoints. I would love to be able to use restify for the API part while leaving the other code to continue doing it's thing.

rgarcia commented Mar 17, 2012

+1. I'd be curious if anyone has a workaround.

Was able to hack a suitable workaround for this, dunno if this is acceptable: https://gist.github.com/2140974

Basically, no change necessary in node-restify. Is this what you guys are looking for? In my case, I need to integrate node-oauth2-provider with Restify, and since that already integrates with Connect, I did what you see in that gist.

Obviously, I haven't completely tested this yet (for one thing, I don't seem to be able to access the session object when there's a session middleware installed), but it does work for me (e.g. you can mount your Restify API at /api without changing the API endpoints).

Interesting approach @jmibanez.

Perhaps @mcavage could add a middleware() method to Restify servers that would expose the plumbing to pipe routes from connect to Restify without requiring internal changes.

What do you think?


mcavage commented Mar 26, 2012

I've thought about this quite a bit, and the thing that worries me here is signing up for compatibility with connect evermore. I don't have control or input over what they decide to do. This seems more in the vein of "if it works, great".

I'm going to close this out with a "won't fix" for now :\

@mcavage mcavage closed this Mar 26, 2012

Some pretty nice versioning techniques could be done with this feature. For reference, I found a nice article explaining how to do it with express.



DonutEspresso commented Jun 30, 2015

@cadesalaberry restify already supports route versioning.

@bardzusny bardzusny referenced this issue in bardzusny/swaggerize-restify Aug 1, 2015


versioning - allow swaggerize() to be called multiple times #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment