all da files
This commit is contained in:
104
node_modules/router/README.md
generated
vendored
Normal file
104
node_modules/router/README.md
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
# Router
|
||||
|
||||
A lean and mean http router for [node.js](http://nodejs.org).
|
||||
It is available through npm:
|
||||
|
||||
npm install router
|
||||
|
||||
## Usage
|
||||
|
||||
Router does one thing and one thing only - route http requests.
|
||||
|
||||
``` js
|
||||
var http = require('http');
|
||||
var router = require('router');
|
||||
var route = router();
|
||||
|
||||
route.get('/', function(req, res) {
|
||||
res.writeHead(200);
|
||||
res.end('hello index page');
|
||||
});
|
||||
|
||||
http.createServer(route).listen(8080); // start the server on port 8080
|
||||
```
|
||||
|
||||
If you want to grap a part of the path you can use capture groups in the pattern:
|
||||
|
||||
``` js
|
||||
route.get('/{base}', function(req, res) {
|
||||
var base = req.params.base; // ex: if the path is /foo/bar, then base = foo
|
||||
});
|
||||
```
|
||||
|
||||
The capture patterns matches until the next `/` or character present after the group
|
||||
|
||||
``` js
|
||||
route.get('/{x}x{y}', function(req, res) {
|
||||
// if the path was /200x200, then req.params = {x:'200', y:'200'}
|
||||
});
|
||||
```
|
||||
|
||||
Optional patterns are supported by adding a `?` at the end
|
||||
|
||||
``` js
|
||||
route.get('/{prefix}?/{top}', function(req, res) {
|
||||
// matches both '/a/b' and '/b'
|
||||
});
|
||||
```
|
||||
|
||||
If you want to just match everything you can use a wildcard `*` which works like unix wildcards
|
||||
|
||||
``` js
|
||||
route.get('/{prefix}/*', function(req, res) {
|
||||
// matches both '/a/', '/a/b', 'a/b/c' and so on.
|
||||
// the value of the wildcard is available through req.params.wildcard
|
||||
});
|
||||
```
|
||||
|
||||
If the standard capture groups aren't expressive enough for you can specify an optional inline regex
|
||||
|
||||
``` js
|
||||
route.get('/{digits}([0-9]+)', function(req, res) {
|
||||
// matches both '/24' and '/424' but not '/abefest' and so on.
|
||||
});
|
||||
```
|
||||
|
||||
You can also use regular expressions and the related capture groups instead:
|
||||
|
||||
``` js
|
||||
route.get(/^\/foo\/(\w+)/, function(req, res) {
|
||||
var group = req.params[1]; // if path is /foo/bar, then group is bar
|
||||
});
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
* `route.get`: Match `GET` requests
|
||||
* `route.post`: Match `POST` requests
|
||||
* `route.put`: Match `PUT` requests
|
||||
* `route.head`: Match `HEAD` requests
|
||||
* `route.del`: Match `DELETE` requests
|
||||
* `route.options`: Match `OPTIONS` requests
|
||||
* `route.all`: Match all above request methods.
|
||||
|
||||
## Error handling
|
||||
|
||||
By default Router will return 404 if you no route matched. If you want to do your own thing you can give it a callback:
|
||||
|
||||
``` js
|
||||
route(req, res, function() {
|
||||
// no route was matched
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
});
|
||||
```
|
||||
|
||||
You can also provide a catch-all to a given route that is called if no route was matched:
|
||||
|
||||
``` js
|
||||
route.get(function(req, res) {
|
||||
// called if no other get route matched
|
||||
res.writeHead(404);
|
||||
res.end('no GET handler found');
|
||||
});
|
||||
```
|
25
node_modules/router/formatter.js
generated
vendored
Normal file
25
node_modules/router/formatter.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
var param = function(val) {
|
||||
return function(map) {
|
||||
return map[val];
|
||||
};
|
||||
};
|
||||
var str = function(val) {
|
||||
return function() {
|
||||
return val;
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = function(format) {
|
||||
if (!format) return null;
|
||||
|
||||
format = format.replace(/\{\*\}/g, '*').replace(/\*/g, '{*}').replace(/:(\w+)/g, '{$1}'); // normalize
|
||||
format = format.match(/(?:[^\{]+)|(?:{[^\}]+\})/g).map(function(item) {
|
||||
return item[0] !== '{' ? str(item) : param(item.substring(1, item.length-1));
|
||||
});
|
||||
|
||||
return function(params) {
|
||||
return format.reduce(function(result, item) {
|
||||
return result+item(params);
|
||||
}, '');
|
||||
};
|
||||
};
|
92
node_modules/router/index.js
generated
vendored
Normal file
92
node_modules/router/index.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
var matcher = require('./matcher');
|
||||
var formatter = require('./formatter');
|
||||
|
||||
var METHODS = ['get', 'post', 'put', 'del' , 'delete', 'head', 'options'];
|
||||
var HTTP_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'DELETE', 'HEAD', 'OPTIONS'];
|
||||
|
||||
var noop = function() {};
|
||||
var error = function(res) {
|
||||
return function() {
|
||||
res.statusCode = 404;
|
||||
res.end();
|
||||
};
|
||||
};
|
||||
var router = function() {
|
||||
var methods = {};
|
||||
var traps = {};
|
||||
|
||||
HTTP_METHODS.forEach(function(method) {
|
||||
methods[method] = [];
|
||||
});
|
||||
|
||||
var route = function(req, res, next) {
|
||||
var method = methods[req.method];
|
||||
var trap = traps[req.method];
|
||||
var index = req.url.indexOf('?');
|
||||
var url = index === -1 ? req.url : req.url.substr(0, index);
|
||||
var i = 0;
|
||||
|
||||
next = next || error(res);
|
||||
if (!method) return next();
|
||||
|
||||
var loop = function(err) {
|
||||
if (err) return next(err);
|
||||
while (i < method.length) {
|
||||
var route = method[i];
|
||||
|
||||
i++;
|
||||
req.params = route.pattern(url);
|
||||
if (!req.params) continue;
|
||||
if (route.rewrite) {
|
||||
req.url = url = route.rewrite(req.params)+(index === -1 ? '' : req.url.substr(index));
|
||||
}
|
||||
route.fn(req, res, loop);
|
||||
return;
|
||||
}
|
||||
if (!trap) return next();
|
||||
trap(req, res, next);
|
||||
};
|
||||
|
||||
loop();
|
||||
};
|
||||
|
||||
METHODS.forEach(function(method, i) {
|
||||
route[method] = function(pattern, rewrite, fn) {
|
||||
if (Array.isArray(pattern)) {
|
||||
pattern.forEach(function(item) {
|
||||
route[method](item, rewrite, fn);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fn && !rewrite) return route[method](null, null, pattern);
|
||||
if (!fn && typeof rewrite === 'string') return route[method](pattern, rewrite, route);
|
||||
if (!fn && typeof rewrite === 'function') return route[method](pattern, null, rewrite);
|
||||
if (!fn) return route;
|
||||
|
||||
(route.onmount || noop)(pattern, rewrite, fn);
|
||||
|
||||
if (!pattern) {
|
||||
traps[HTTP_METHODS[i]] = fn;
|
||||
return route;
|
||||
}
|
||||
|
||||
methods[HTTP_METHODS[i]].push({
|
||||
pattern:matcher(pattern),
|
||||
rewrite:formatter(rewrite),
|
||||
fn:fn
|
||||
});
|
||||
return route;
|
||||
};
|
||||
});
|
||||
route.all = function(pattern, rewrite, fn) {
|
||||
METHODS.forEach(function(method) {
|
||||
route[method](pattern, rewrite, fn);
|
||||
});
|
||||
return route;
|
||||
};
|
||||
|
||||
return route;
|
||||
};
|
||||
|
||||
module.exports = router;
|
51
node_modules/router/matcher.js
generated
vendored
Normal file
51
node_modules/router/matcher.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
var decode = function(str) {
|
||||
try {
|
||||
return decodeURIComponent(str);
|
||||
} catch(err) {
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = function(pattern) {
|
||||
if (typeof pattern !== 'string') { // regex
|
||||
return function(url) {
|
||||
return url.match(pattern);
|
||||
};
|
||||
}
|
||||
|
||||
var keys = [];
|
||||
|
||||
pattern = pattern.replace(/:(\w+)/g, '{$1}').replace('{*}', '*'); // normalize
|
||||
pattern = pattern.replace(/(\/)?(\.)?\{([^}]+)\}(?:\(([^)]*)\))?(\?)?/g, function(match, slash, dot, key, capture, opt, offset) {
|
||||
var incl = (pattern[match.length+offset] || '/') === '/';
|
||||
|
||||
keys.push(key);
|
||||
|
||||
return (incl ? '(?:' : '')+(slash || '')+(incl ? '' : '(?:')+(dot || '')+'('+(capture || '[^/]+')+'))'+(opt || '');
|
||||
});
|
||||
pattern = pattern.replace(/([\/.])/g, '\\$1').replace(/\*/g, '(.+)');
|
||||
pattern = new RegExp('^'+pattern+'[\\/]?$', 'i');
|
||||
|
||||
return function(str) {
|
||||
var match = str.match(pattern);
|
||||
|
||||
if (!match) {
|
||||
return match;
|
||||
}
|
||||
|
||||
var map = {};
|
||||
|
||||
match.slice(1).forEach(function(param, i) {
|
||||
var k = keys[i] = keys[i] || 'wildcard';
|
||||
|
||||
param = param && decode(param);
|
||||
map[k] = map[k] ? [].concat(map[k]).concat(param) : param;
|
||||
});
|
||||
|
||||
if (map.wildcard) {
|
||||
map['*'] = map.wildcard;
|
||||
}
|
||||
|
||||
return map;
|
||||
};
|
||||
};
|
30
node_modules/router/package.json
generated
vendored
Normal file
30
node_modules/router/package.json
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "router",
|
||||
"version": "0.6.2",
|
||||
"description": "A lean and mean http router",
|
||||
"keywords": [
|
||||
"connect",
|
||||
"middleware",
|
||||
"router",
|
||||
"route",
|
||||
"http"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/gett/router.git"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Mathias Buus Madsen",
|
||||
"email": "m@ge.tt"
|
||||
},
|
||||
{
|
||||
"name": "Ian Jorgensen"
|
||||
}
|
||||
],
|
||||
"dependencies": {},
|
||||
"readme": "# Router\n\nA lean and mean http router for [node.js](http://nodejs.org). \nIt is available through npm:\n\n\tnpm install router\n\t\n## Usage\n\nRouter does one thing and one thing only - route http requests.\n\n``` js\nvar http = require('http');\nvar router = require('router');\nvar route = router();\n\nroute.get('/', function(req, res) {\n\tres.writeHead(200);\n\tres.end('hello index page');\n});\n\nhttp.createServer(route).listen(8080); // start the server on port 8080\n```\n\nIf you want to grap a part of the path you can use capture groups in the pattern:\n\n``` js\nroute.get('/{base}', function(req, res) {\n\tvar base = req.params.base; // ex: if the path is /foo/bar, then base = foo\n});\n```\n\nThe capture patterns matches until the next `/` or character present after the group\n\n``` js\nroute.get('/{x}x{y}', function(req, res) {\n\t// if the path was /200x200, then req.params = {x:'200', y:'200'}\n});\n```\n\nOptional patterns are supported by adding a `?` at the end\n\n``` js\nroute.get('/{prefix}?/{top}', function(req, res) {\n\t// matches both '/a/b' and '/b'\n});\n```\n\nIf you want to just match everything you can use a wildcard `*` which works like unix wildcards\n\n``` js\nroute.get('/{prefix}/*', function(req, res) {\n\t// matches both '/a/', '/a/b', 'a/b/c' and so on.\n\t// the value of the wildcard is available through req.params.wildcard\n});\n```\n\nIf the standard capture groups aren't expressive enough for you can specify an optional inline regex \n\n``` js\nroute.get('/{digits}([0-9]+)', function(req, res) {\n\t// matches both '/24' and '/424' but not '/abefest' and so on.\n});\n```\n\nYou can also use regular expressions and the related capture groups instead:\n\n``` js\nroute.get(/^\\/foo\\/(\\w+)/, function(req, res) {\n\tvar group = req.params[1]; // if path is /foo/bar, then group is bar\n});\n```\n\n## Methods\n\n* `route.get`: Match `GET` requests\n* `route.post`: Match `POST` requests\n* `route.put`: Match `PUT` requests\n* `route.head`: Match `HEAD` requests \n* `route.del`: Match `DELETE` requests\n* `route.options`: Match `OPTIONS` requests\n* `route.all`: Match all above request methods.\n\n## Error handling\n\nBy default Router will return 404 if you no route matched. If you want to do your own thing you can give it a callback:\n\n``` js\nroute(req, res, function() {\n\t// no route was matched\n\tres.writeHead(404);\n\tres.end();\n});\n```\n\nYou can also provide a catch-all to a given route that is called if no route was matched:\n\n``` js\nroute.get(function(req, res) {\n\t// called if no other get route matched\n\tres.writeHead(404);\n\tres.end('no GET handler found');\n});\n```",
|
||||
"readmeFilename": "README.md",
|
||||
"_id": "router@0.6.2",
|
||||
"_from": "router@"
|
||||
}
|
16
node_modules/router/tests/1-get.js
generated
vendored
Normal file
16
node_modules/router/tests/1-get.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
var assert = require('assert');
|
||||
var route = require('../index')();
|
||||
|
||||
var res = {end:function() {}};
|
||||
var count = 0;
|
||||
|
||||
route.get('/', function(req, res) {
|
||||
assert.equal(req.method, 'GET');
|
||||
assert.equal(req.url, '/');
|
||||
count++;
|
||||
});
|
||||
|
||||
route({method:'GET', url:'/'},res);
|
||||
route({method:'NOT_GET', url:'/'},res);
|
||||
|
||||
assert.equal(count, 1);
|
29
node_modules/router/tests/2-get.js
generated
vendored
Normal file
29
node_modules/router/tests/2-get.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
var assert = require('assert');
|
||||
var route = require('../index')();
|
||||
|
||||
var res = {end:function() {}};
|
||||
var a = 0;
|
||||
var b = 0;
|
||||
|
||||
route.get('/', function(req, res) {
|
||||
assert.equal(req.method, 'GET');
|
||||
assert.ok(req.url in {'/':1,'/?query':1});
|
||||
a++;
|
||||
});
|
||||
route.get('/b', function(req, res) {
|
||||
assert.equal(req.method, 'GET');
|
||||
assert.ok(req.url in {'/b':1,'/b?query':1});
|
||||
b++;
|
||||
});
|
||||
|
||||
route({method:'GET', url:'/'},res);
|
||||
route({method:'GET', url:'/?query'},res);
|
||||
route({method:'GET', url:'/query'},res);
|
||||
route({method:'NOT_GET', url:'/'},res);
|
||||
|
||||
route({method:'GET', url:'/b'},res);
|
||||
route({method:'GET', url:'/b?query'},res);
|
||||
route({method:'GET', url:'/query'},res);
|
||||
|
||||
assert.equal(a, 2);
|
||||
assert.equal(b, 2);
|
29
node_modules/router/tests/all-trap.js
generated
vendored
Normal file
29
node_modules/router/tests/all-trap.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
var assert = require('assert');
|
||||
var route = require('../index')();
|
||||
|
||||
var order = ['GET','GET','GET','POST','POST','POST'];
|
||||
var res = {end:function() {}};
|
||||
var count = 0;
|
||||
var a = 0;
|
||||
|
||||
route.get('/', function() {
|
||||
a++;
|
||||
});
|
||||
route.all(function(req, res) {
|
||||
assert.equal(req.method, order[count]);
|
||||
assert.notEqual(req.url, '/');
|
||||
count++;
|
||||
});
|
||||
|
||||
route({method:'GET', url:'/'},res);
|
||||
route({method:'GET', url:'/?query'},res);
|
||||
route({method:'GET', url:'/a'},res);
|
||||
route({method:'GET', url:'/abe'},res);
|
||||
route({method:'GET', url:'/abefest'},res);
|
||||
route({method:'POST', url:'/a'},res);
|
||||
route({method:'POST', url:'/abe'},res);
|
||||
route({method:'POST', url:'/abefest'},res);
|
||||
route({method:'NOT_GET', url:'/'},res);
|
||||
|
||||
assert.equal(count, 6);
|
||||
assert.equal(a, 2);
|
30
node_modules/router/tests/all.js
generated
vendored
Normal file
30
node_modules/router/tests/all.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
var assert = require('assert');
|
||||
var route = require('../index')();
|
||||
|
||||
var res = {end:function() {}};
|
||||
var count = 0;
|
||||
var order = ['GET','POST','OPTIONS','HEAD','DELETE','PUT'];
|
||||
|
||||
route.all('/', function(req, res) {
|
||||
assert.equal(req.method, order[count]);
|
||||
assert.equal(req.url, '/');
|
||||
count++;
|
||||
});
|
||||
|
||||
route({method:'GET', url:'/'},res);
|
||||
route({method:'POST', url:'/'},res);
|
||||
route({method:'OPTIONS', url:'/'},res);
|
||||
route({method:'HEAD', url:'/'},res);
|
||||
route({method:'DELETE', url:'/'},res);
|
||||
route({method:'PUT', url:'/'},res);
|
||||
|
||||
route({method:'GET', url:'/a'},res);
|
||||
route({method:'POST', url:'/a'},res);
|
||||
route({method:'OPTIONS', url:'/a'},res);
|
||||
route({method:'HEAD', url:'/a'},res);
|
||||
route({method:'DELETE', url:'/a'},res);
|
||||
route({method:'PUT', url:'/a'},res);
|
||||
|
||||
route({method:'NOT_GET', url:'/'},res);
|
||||
|
||||
assert.equal(count, 6);
|
29
node_modules/router/tests/callback.js
generated
vendored
Normal file
29
node_modules/router/tests/callback.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
var assert = require('assert');
|
||||
var route = require('../index')();
|
||||
|
||||
var res = {end:function() {}};
|
||||
var count = 0;
|
||||
|
||||
route.get('/', function(req, res, callback) {
|
||||
assert.equal(req.method, 'GET');
|
||||
assert.equal(req.url, '/');
|
||||
count++;
|
||||
callback(new Error('/'));
|
||||
});
|
||||
route.get('/ok', function(req, res, callback) {
|
||||
assert.equal(req.method, 'GET');
|
||||
assert.equal(req.url, '/ok');
|
||||
count++;
|
||||
callback();
|
||||
});
|
||||
|
||||
route({method:'GET', url:'/'}, res, function(err) {
|
||||
count++;
|
||||
assert.equal(err.message, '/');
|
||||
});
|
||||
route({method:'GET', url:'/ok'}, res, function(err) {
|
||||
count++;
|
||||
assert.equal(err, undefined);
|
||||
});
|
||||
|
||||
assert.equal(count, 4);
|
16
node_modules/router/tests/decode.js
generated
vendored
Normal file
16
node_modules/router/tests/decode.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
var assert = require('assert');
|
||||
var route = require('../index')();
|
||||
|
||||
var res = {end:function() {}};
|
||||
var count = 0;
|
||||
|
||||
route.get('/{a}/*', function(req, res) {
|
||||
assert.equal(req.params.a, 'a c');
|
||||
assert.equal(req.params.wildcard, 'b c/c d');
|
||||
assert.equal(req.url, '/a%20c/b%20c/c%20d');
|
||||
count++;
|
||||
});
|
||||
|
||||
route({method:'GET', url:'/a%20c/b%20c/c%20d'},res);
|
||||
|
||||
assert.equal(count, 1);
|
41
node_modules/router/tests/fallthrough.js
generated
vendored
Normal file
41
node_modules/router/tests/fallthrough.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
var assert = require('assert');
|
||||
var route = require('../index')();
|
||||
|
||||
var res = {end:function() {}};
|
||||
var count = 0;
|
||||
|
||||
route.get('/', function(req, res, callback) {
|
||||
assert.equal(req.method, 'GET');
|
||||
assert.equal(req.url, '/');
|
||||
assert.equal(count, 0);
|
||||
count++;
|
||||
callback();
|
||||
});
|
||||
route.get('/', function(req, res, callback) {
|
||||
assert.equal(req.method, 'GET');
|
||||
assert.equal(req.url, '/');
|
||||
assert.equal(count, 1);
|
||||
count++;
|
||||
callback();
|
||||
});
|
||||
|
||||
route.get('/err', function(req, res, callback) {
|
||||
assert.equal(req.method, 'GET');
|
||||
assert.equal(req.url, '/err');
|
||||
count++;
|
||||
callback(new Error('/err'));
|
||||
});
|
||||
route.get('/err', function(req, res, callback) {
|
||||
assert.ok(false);
|
||||
});
|
||||
|
||||
route({method:'GET', url:'/'}, res, function() {
|
||||
assert.equal(count, 2);
|
||||
count++;
|
||||
});
|
||||
route({method:'GET', url:'/err'}, res, function(err) {
|
||||
assert.equal(err.message, '/err');
|
||||
count++;
|
||||
});
|
||||
|
||||
assert.equal(count, 5);
|
27
node_modules/router/tests/get-to-all.js
generated
vendored
Normal file
27
node_modules/router/tests/get-to-all.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
var assert = require('assert');
|
||||
var route = require('../index')();
|
||||
|
||||
var res = {end:function() {}};
|
||||
var count = 0;
|
||||
|
||||
route.get('/', function(req, res, callback) {
|
||||
assert.equal(req.method, 'GET');
|
||||
assert.equal(req.url, '/');
|
||||
assert.equal(count, 0);
|
||||
count++;
|
||||
callback();
|
||||
});
|
||||
route.all('/', function(req, res, callback) {
|
||||
assert.equal(req.method, 'GET');
|
||||
assert.equal(req.url, '/');
|
||||
assert.equal(count, 1);
|
||||
count++;
|
||||
callback();
|
||||
});
|
||||
|
||||
route({method:'GET', url:'/'}, res, function() {
|
||||
assert.equal(count, 2);
|
||||
count++;
|
||||
});
|
||||
|
||||
assert.equal(count, 3);
|
37
node_modules/router/tests/index.js
generated
vendored
Normal file
37
node_modules/router/tests/index.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
var fs = require('fs');
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
var tests = fs.readdirSync(__dirname).filter(function(file) {
|
||||
return !fs.statSync(__dirname+'/'+file).isDirectory();
|
||||
}).filter(function(file) {
|
||||
return file !== 'index.js';
|
||||
});
|
||||
|
||||
var cnt = 0;
|
||||
var all = tests.length;
|
||||
|
||||
var loop = function() {
|
||||
var next = tests.shift();
|
||||
|
||||
if (!next) {
|
||||
console.log('\033[32m[ok]\033[39m all ok');
|
||||
return;
|
||||
}
|
||||
|
||||
exec('node '+__dirname+'/'+next, function(err) {
|
||||
cnt++;
|
||||
|
||||
if (err) {
|
||||
console.error('\033[31m[err]\033[39m '+cnt+'/'+all+' - '+next);
|
||||
console.error('\n '+(''+err.stack).split('\n').join('\n ')+'\n');
|
||||
process.exit(1);
|
||||
return;
|
||||
} else {
|
||||
console.log('\033[32m[ok]\033[39m '+cnt+'/'+all+' - '+next);
|
||||
}
|
||||
|
||||
setTimeout(loop, 100);
|
||||
});
|
||||
};
|
||||
|
||||
loop();
|
29
node_modules/router/tests/params.js
generated
vendored
Normal file
29
node_modules/router/tests/params.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
var assert = require('assert');
|
||||
var route = require('../index')();
|
||||
|
||||
var count = 0;
|
||||
|
||||
route.get('/{test}', function(req, res) {
|
||||
assert.equal(req.params.test, 'ok')
|
||||
assert.ok(req.url in {'/ok':1, '/ok/':1});
|
||||
count++;
|
||||
});
|
||||
route.get('/{a}/{b}', function(req, res) {
|
||||
assert.equal(req.params.a, 'a-ok');
|
||||
assert.equal(req.params.b, 'b-ok');
|
||||
assert.equal(req.url, '/a-ok/b-ok');
|
||||
count++;
|
||||
});
|
||||
route.get('/{a}/*', function(req, res) {
|
||||
assert.equal(req.params.a, 'a');
|
||||
assert.equal(req.params.wildcard, 'b/c');
|
||||
assert.equal(req.url, '/a/b/c');
|
||||
count++;
|
||||
});
|
||||
|
||||
route({method:'GET', url:'/ok'});
|
||||
route({method:'GET', url:'/ok/'});
|
||||
route({method:'GET', url:'/a-ok/b-ok'});
|
||||
route({method:'GET', url:'/a/b/c'});
|
||||
|
||||
assert.equal(count, 4);
|
25
node_modules/router/tests/trap.js
generated
vendored
Normal file
25
node_modules/router/tests/trap.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
var assert = require('assert');
|
||||
var route = require('../index')();
|
||||
|
||||
var res = {end:function() {}};
|
||||
var count = 0;
|
||||
var a = 0;
|
||||
|
||||
route.get('/', function() {
|
||||
a++;
|
||||
});
|
||||
route.get(function(req, res) {
|
||||
assert.equal(req.method, 'GET');
|
||||
assert.notEqual(req.url, '/');
|
||||
count++;
|
||||
});
|
||||
|
||||
route({method:'GET', url:'/'},res);
|
||||
route({method:'GET', url:'/?query'},res);
|
||||
route({method:'GET', url:'/a'},res);
|
||||
route({method:'GET', url:'/abe'},res);
|
||||
route({method:'GET', url:'/abefest'},res);
|
||||
route({method:'NOT_GET', url:'/'},res);
|
||||
|
||||
assert.equal(count, 3);
|
||||
assert.equal(a, 2);
|
Reference in New Issue
Block a user