This repository has been archived by the owner on Oct 27, 2019. It is now read-only.
forked from senchalabs/connect
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
/*! | ||
* Connect - query | ||
* Copyright(c) 2011 TJ Holowaychuk | ||
* Copyright(c) 2011 Sencha Inc. | ||
* MIT Licensed | ||
*/ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var qs = require('qs') | ||
, parse = require('url').parse; | ||
|
||
/** | ||
* Automatically parse the query-string when available, | ||
* populating the `req.query` object. | ||
* | ||
* @return {Function} | ||
* @api public | ||
*/ | ||
|
||
module.exports = function query(){ | ||
return function query(req, res, next){ | ||
req.query = ~req.url.indexOf('?') | ||
? qs.parse(parse(req.url).query) | ||
: {}; | ||
next(); | ||
}; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"files":["lib/connect.js","lib/http.js","lib/https.js","lib/index.js","lib/middleware/basicAuth.js","lib/middleware/bodyParser.js","lib/middleware/compiler.js","lib/middleware/cookieParser.js","lib/middleware/directory.js","lib/middleware/errorHandler.js","lib/middleware/favicon.js","lib/middleware/limit.js","lib/middleware/logger.js","lib/middleware/methodOverride.js","lib/middleware/profiler.js","lib/middleware/responseTime.js","lib/middleware/router.js","lib/middleware/session/cookie.js","lib/middleware/session/memory.js","lib/middleware/session/session.js","lib/middleware/session/store.js","lib/middleware/session.js","lib/middleware/static.js","lib/middleware/vhost.js","lib/patch.js","lib/utils.js"]} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var connect = require('connect') | ||
, assert = require('assert') | ||
, http = require('http'); | ||
|
||
var app = connect( | ||
connect.query() | ||
, function(req, res){ | ||
res.end(JSON.stringify(req.query)); | ||
} | ||
); | ||
|
||
module.exports = { | ||
'test empty query string object': function(){ | ||
assert.response(app, | ||
{ url: '/' }, | ||
{ body: '{}' }); | ||
}, | ||
|
||
'test query string': function(){ | ||
assert.response(app, | ||
{ url: '/?foo=bar' }, | ||
{ body: '{"foo":"bar"}' }); | ||
} | ||
}; |