Skip to content

Instantly share code, notes, and snippets.

@jcolebrand
Created January 19, 2013 03:24
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 jcolebrand/34db9631a9132293d7b6 to your computer and use it in GitHub Desktop.
Save jcolebrand/34db9631a9132293d7b6 to your computer and use it in GitHub Desktop.
var _=require('underscore');
module.exports = function(router) {
/* router contains the config as router.config */
var config = router.config,
databaseListener = require('./databaseListener.js')(router);
function _baseRequestListener(req, resp) { /* do things here that run a site */
// TODO: handle this if we are a POST, etc request, else passthrough if we are GET, etc.
switch(req.method) {
case 'GET':
case 'OPTIONS':
case 'DELETE':
case 'HEAD':
req.body = req.form = {};
router.route(req, resp);
break;
case 'POST':
case 'PUT':
case 'PATCH':
require('./app/connect/bodyParser.js')(appConfig.bodyParser)(req, res, function(errs) {
router.route(req, res, errs);
})
break;
case 'TRACE':
// TODO: convert req to res and send.
break;
case 'CONNECT':
default:
// TODO: fail for unsupported command
break;
}
// TODO: Handle this case -> Accept-Encoding:gzip,deflate,sdch
// see http://stackoverflow.com/questions/9969253/node-js-http-server-with-compression-sending-variable-as-response
console.log('exiting cleanly');
process.exit();
};
return {
requestListener: _baseRequestListener
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment