Created
January 7, 2014 23:38
-
-
Save mwbrooks/8308963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* Module dependencies. | |
*/ | |
var connect = require('connect'), | |
http = require('http'), | |
app = connect(); | |
/** | |
* Middleware #1 | |
*/ | |
app.use(function(req, res, next) { | |
console.log('middleware #1'); | |
next(); | |
}); | |
/** | |
* Middleware #2 | |
*/ | |
app.use(function(req, res, next) { | |
console.log('middleware #2'); | |
// res.writeHead(200, {'Content-Type': 'text/plain'}); | |
// res.end('Hello World\n'); | |
next(); | |
}); | |
/** | |
* Public middleware interface. | |
* | |
* Delegates to our internal middlware stack. | |
*/ | |
module.exports = function(req, res, next) { | |
app.handle(req, res, next); | |
}; | |
/** | |
* Listener helper. | |
*/ | |
module.exports.listen = function() { | |
var server = http.createServer(module.exports); | |
return server.listen.apply(server, arguments); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* Module dependencies. | |
*/ | |
var connect = require('connect'), | |
soundwave = require('./soundwave'); | |
/*! | |
* Create a server that uses the soundwave as middleware | |
*/ | |
// create a server | |
var app = connect(); | |
// middleware A | |
app.use(function(req, res, next) { | |
console.log('middleware A'); | |
next(); | |
}); | |
// middleware soundwave | |
app.use(soundwave); | |
// middleware B | |
app.use(function(req, res, next) { | |
console.log('middleware B'); | |
next(); | |
}); | |
// run server | |
app.listen(3000, function() { | |
console.log('running on port 3000'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment