Comparing version 2.3.0 to 2.4.0
@@ -14,4 +14,4 @@ delete require.cache[__filename]; | ||
} else if (param instanceof RegExp) { | ||
ret = new RegExp(url.replace(/([\.\-])/g, '\\$1') + '/' + | ||
param.toString().replace(/^\/(\\\/)*|\/$/g, '')); | ||
ret = new RegExp('^' + url.replace(/([\.\-])/g, '\\$1') + '/' + | ||
param.toString().replace(/^\/(\\\/)*|\/$/g, '') + '$'); | ||
} | ||
@@ -18,0 +18,0 @@ return ret; |
{ | ||
"name": "rainbow", | ||
"description": "Express router middleware for RESTful API base on certain folder path", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"author": "mytharcher <mytharcher@gmail.com>", | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -14,4 +14,4 @@ var express = require('express'); | ||
ignore: [ | ||
'ignore.me.js', | ||
'**.spec.js' | ||
'**/ignore.me.js', | ||
'**/*.spec.js' | ||
] | ||
@@ -26,2 +26,4 @@ } | ||
app.use('/public', express.static(path.join(__dirname, 'public'))); | ||
var server; | ||
@@ -28,0 +30,0 @@ |
125
test/test.js
@@ -12,2 +12,6 @@ var assert = require('assert'); | ||
var file = axios.create({ | ||
baseURL: `http://localhost:${PORT}/` | ||
}); | ||
before(function (done) { | ||
@@ -28,6 +32,7 @@ server.start(PORT, done); | ||
console.error(http.response.status); | ||
assert.fail(); | ||
}).then(done, done); | ||
}); | ||
it('"GET /(\\d+)/" with regexp number params should be ok', function (done) { | ||
it('GET /(\\d+)/ with regexp number params should be ok', function (done) { | ||
request.get('/123').then(function (res) { | ||
@@ -38,2 +43,3 @@ assert.equal(res.status, 200); | ||
console.error(http.response.status); | ||
assert.fail(); | ||
}).then(done, done); | ||
@@ -48,11 +54,13 @@ }); | ||
console.error(http.response.status); | ||
assert.fail(); | ||
}).then(done, done); | ||
}); | ||
it('GET /some-path/123 with regexp number params should be ok', function (done) { | ||
request.get('/some-path/123').then(function (res) { | ||
it('GET /some-path/234 with regexp number params should be ok', function (done) { | ||
request.get('/some-path/234').then(function (res) { | ||
assert.equal(res.status, 200); | ||
assert.equal(res.data, 123); | ||
assert.equal(res.data, 234); | ||
}, function (http) { | ||
console.error(http.response.status); | ||
assert.fail(); | ||
}).then(done, done); | ||
@@ -67,5 +75,6 @@ }); | ||
assert.equal(res.data, '1'); | ||
}).catch(function (http) { | ||
}, function (http) { | ||
console.error(http.response.status); | ||
}).then(done); | ||
assert.fail(); | ||
}).then(done, done); | ||
}); | ||
@@ -77,5 +86,6 @@ | ||
assert.equal(res.data, '1'); | ||
}).catch(function (http) { | ||
}, function (http) { | ||
console.error(http.response.status); | ||
}).then(done); | ||
assert.fail(); | ||
}).then(done, done); | ||
}); | ||
@@ -87,2 +97,3 @@ }); | ||
request.get('/sub.action').then(function (res) { | ||
assert.fail(); | ||
}).catch(function (http) { | ||
@@ -96,23 +107,26 @@ assert.equal(http.response.status, 404); | ||
assert.equal(res.data, 'ok'); | ||
}).catch(function (http) { | ||
}, function (http) { | ||
console.error(http.response.status); | ||
}).then(done); | ||
assert.fail(); | ||
}).then(done, done); | ||
}); | ||
it('GET /sub.action/:id should be the id', function (done) { | ||
request.get('/sub.action/123').then(function (res) { | ||
request.get('/sub.action/345').then(function (res) { | ||
assert.equal(res.status, 200); | ||
assert.equal(res.data, '123'); | ||
}).catch(function (http) { | ||
assert.equal(res.data, '345'); | ||
}, function (http) { | ||
console.error(http.response.status); | ||
}).then(done); | ||
assert.fail(); | ||
}).then(done, done); | ||
}); | ||
it('GET /sub.action/:id/test should be the id', function (done) { | ||
request.get('/sub.action/123/test').then(function (res) { | ||
request.get('/sub.action/456/test').then(function (res) { | ||
assert.equal(res.status, 200); | ||
assert.equal(res.data, '123'); | ||
}).catch(function (http) { | ||
assert.equal(res.data, '456'); | ||
}, function (http) { | ||
console.error(http.response.status); | ||
}).then(done); | ||
assert.fail(); | ||
}).then(done, done); | ||
}); | ||
@@ -125,9 +139,13 @@ }); | ||
assert.equal(res.status, 204); | ||
}, function (http) { | ||
assert.fail(); | ||
}).then(done); | ||
}); | ||
it('GET /with-params/123 should be 123', function (done) { | ||
request.get('/with-params/123').then(function (res) { | ||
it('GET /with-params/567 should be 567', function (done) { | ||
request.get('/with-params/567').then(function (res) { | ||
assert.equal(res.status, 200); | ||
assert.equal(res.data, '123'); | ||
assert.equal(res.data, '567'); | ||
}, function (http) { | ||
assert.fail(); | ||
}).then(done); | ||
@@ -138,5 +156,6 @@ }); | ||
request.get('/with-params/abc').then(function (res) { | ||
}).catch(function (http) { | ||
assert.fail(); | ||
}, function (http) { | ||
assert.equal(http.response.status, 404); | ||
}).then(done); | ||
}).then(done, done); | ||
}); | ||
@@ -148,3 +167,5 @@ | ||
assert.equal(res.data, 'abc'); | ||
}).then(done); | ||
}, function (http) { | ||
assert.fail(); | ||
}).then(done, done); | ||
}); | ||
@@ -154,7 +175,18 @@ }); | ||
describe('ignored controller files', function () { | ||
it('GET /index.spec should be 404', function (done) { | ||
request.get('/index.spec').then(function (res) { | ||
console.log(res.status); | ||
assert.fail(); | ||
}, function (http) { | ||
assert.equal(http.response.status, 404); | ||
}).then(done, done); | ||
}); | ||
it('GET /ignore.me should be 404', function (done) { | ||
request.get('/ignore.me').then(function (res) { | ||
}).catch(function (http) { | ||
console.log(res.status); | ||
assert.fail(); | ||
}, function (http) { | ||
assert.equal(http.response.status, 404); | ||
}).then(done); | ||
}).then(done, done); | ||
}); | ||
@@ -170,2 +202,3 @@ }); | ||
console.error(http.response.status); | ||
assert.fail(); | ||
}).then(done, done); | ||
@@ -176,2 +209,3 @@ }); | ||
request.get('/abs/some-path/').then(function (res) { | ||
assert.fail(); | ||
console.error('should not get here'); | ||
@@ -183,2 +217,18 @@ }, function (http) { | ||
it('GET /abs/some-path/678 (strict) should be 678', function (done) { | ||
request.get('/abs/some-path/678').then(function (res) { | ||
assert.equal(res.data, '678'); | ||
}, function (http) { | ||
assert.fail(); | ||
}).then(done, done); | ||
}); | ||
it('GET /abs/some-path/678/abc.txt (strict) should be 404', function (done) { | ||
request.get('/abs/some-path/678/abc.txt').then(function (res) { | ||
assert.fail(res.status, 404); | ||
}, function (http) { | ||
assert.equal(http.response.status, 404); | ||
}).then(done, done); | ||
}); | ||
it('GET /abs/all.filters method should get the value', function (done) { | ||
@@ -188,5 +238,26 @@ request.get('/abs/all.filters').then(function (res) { | ||
}).catch(function (http) { | ||
assert.fail(); | ||
console.error(http.response.status); | ||
}).then(done); | ||
}).then(done, done); | ||
}); | ||
}); | ||
describe('static paths', function () { | ||
it('GET /public/ should be the index file content', function (done) { | ||
file.get('/public/').then(function (res) { | ||
assert.equal(res.status, 200); | ||
assert.equal(res.data, 'hello'); | ||
}, function (http) { | ||
assert.fail(http.response.status, 200); | ||
}).then(done, done); | ||
}); | ||
it('GET /public/some-path/678/abc.txt should be the file content', function (done) { | ||
file.get('/public/some-path/678/abc.txt').then(function (res) { | ||
assert.equal(res.status, 200); | ||
assert.equal(res.data, 'test'); | ||
}, function (http) { | ||
assert.fail(http.response.status, 200); | ||
}).then(done, done); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19537
15
368
0