Skip to content

Instantly share code, notes, and snippets.

@leoh
Forked from jmibanez/gist:2140974
Last active August 29, 2015 14:06
Show Gist options
  • Save leoh/17b9d3a049fb8a2733e8 to your computer and use it in GitHub Desktop.
Save leoh/17b9d3a049fb8a2733e8 to your computer and use it in GitHub Desktop.
A complete example of using restify with connect
// Restify server config here
var restify = require('restify');
var server = restify.createServer({
name: 'restify-test',
version: '1.0.0'
});
function respond(req, res, next) {
res.send('hello ' + req.params.name);
next();
}
server.get('/hello/:name', respond);
// Connect config here
var connect = require("connect");
var connectApp = connect()
.use(connect.logger())
.use(connect.bodyParser())
.use(connect.query())
.use(connect.cookieParser())
// And this is where the magic happens
.use("/api", function (req, res) {
server.server.emit('request', req, res);
});
connectApp.listen(8080);
//please test at localhost:8080/api/hello/leo
{
"name": "restify-test",
"description": "restify-test",
"version": "0.0.1",
"author": "Leo",
"engines": {
"node": ">= 0.4.0"
},
"devDependencies": {
"connect": "^2.25.9",
"restify": "^2.8.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment