Skip to content

Instantly share code, notes, and snippets.

@mwbrooks
Created January 7, 2014 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwbrooks/8308963 to your computer and use it in GitHub Desktop.
Save mwbrooks/8308963 to your computer and use it in GitHub Desktop.
/*!
* 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);
}
/*!
* 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