-
-
Save jcolebrand/34db9631a9132293d7b6 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
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