Permalink
Browse files

Using connect's exports instead of express'es fixed the bodyParser issue

  • Loading branch information...
bbyars committed May 29, 2011
1 parent 95a5151 commit d8fe0ec90d382dfc2f1b35c5738dd18788e9b75d
Showing with 2 additions and 23 deletions.
  1. +0 −1 TODO.md
  2. +2 −22 server/lib/controlServer.js
View
@@ -1,7 +1,6 @@
## Refactorings
* filter out stub matching logic into module, unit test
* Remove string.format for something more javascript like
-* Use connect's bodyParser rather than re-implementing
## Build
* packages: npm, brew
@@ -18,26 +18,6 @@ var create = function (port) {
contentHeader = {'Content-Type': CONTENT_TYPE},
app;
- // express.bodyParser() stopped working for me.
- // git bisect showed that it doesn't work in source history either,
- // pointing to environmental issues, but I couldn't figure out what
- // changed (same version of node, express, connect, etc)...
- function bodyParser(request, response, next) {
- request.rawBody = '';
- request.setEncoding('utf8');
-
- request.on('data', function (chunk) {
- request.rawBody += chunk;
- });
-
- request.on('end', function () {
- if (request.rawBody !== '') {
- request.body = JSON.parse(request.rawBody);
- }
- next();
- });
- }
-
function createAbsoluteUrl(request, response, next) {
var host = request.headers.host || 'localhost:' + port;
response.absoluteUrl = function (endpoint, serverPort) {
@@ -107,8 +87,8 @@ var create = function (port) {
}
app = express.createServer(
- express.logger({format: '[ROOT]: :method :url'}),
- bodyParser,
+ connect.logger({format: '[ROOT]: :method :url'}),
+ connect.bodyParser(),
createAbsoluteUrl);
app.listen(port);
console.log('HTTPMock running at http://localhost:{0}'.format(port));

0 comments on commit d8fe0ec

Please sign in to comment.