From 9342ada5f169ab259ab4c56d1a09c06dd887a919 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 19 Jul 2018 15:04:36 -0400 Subject: [PATCH 001/207] Drop support for Node.js below 0.10 --- .travis.yml | 2 -- HISTORY.md | 5 +++++ index.js | 9 ++------- package.json | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0c899b4..bcfa6aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: node_js node_js: - - "0.8" - "0.10" - "0.12" - "1.8" @@ -21,7 +20,6 @@ before_install: # Skip updating shrinkwrap / lock - "npm config set shrinkwrap false" # Setup Node.js version-specific dependencies - - "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul" - "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev eslint eslint-plugin-markdown" # Update Node.js modules - "test ! -d node_modules || npm prune" diff --git a/HISTORY.md b/HISTORY.md index 62619f8..baeede4 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +2.x +=== + + * Drop support for Node.js below 0.10 + 1.3.3 / 2018-07-06 ================== diff --git a/index.js b/index.js index a8927da..7c68516 100644 --- a/index.js +++ b/index.js @@ -28,11 +28,6 @@ var setPrototypeOf = require('setprototypeof') var slice = Array.prototype.slice -/* istanbul ignore next */ -var defer = typeof setImmediate === 'function' - ? setImmediate - : function(fn){ process.nextTick(fn.bind.apply(fn, arguments)) } - /** * Expose `Router`. */ @@ -208,13 +203,13 @@ Router.prototype.handle = function handle(req, res, callback) { // signal to exit router if (layerError === 'router') { - defer(done, null) + setImmediate(done, null) return } // no more matching layers if (idx >= stack.length) { - defer(done, layerError) + setImmediate(done, layerError) return } diff --git a/package.json b/package.json index a340010..20eafc2 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "index.js" ], "engines": { - "node": ">= 0.8" + "node": ">= 0.10" }, "scripts": { "lint": "eslint --plugin markdown --ext js,md .", From 7cf14eabf6d36eeaafd0c2986e61fb9d5de7cd0b Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 19 Jul 2018 15:05:47 -0400 Subject: [PATCH 002/207] deps: debug@3.1.0 --- HISTORY.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index baeede4..7a388b2 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,12 @@ === * Drop support for Node.js below 0.10 + * deps: debug@3.1.0 + - Add `DEBUG_HIDE_DATE` environment variable + - Change timer to per-namespace instead of global + - Change non-TTY date format + - Remove `DEBUG_FD` environment variable support + - Support 256 namespace colors 1.3.3 / 2018-07-06 ================== diff --git a/package.json b/package.json index 20eafc2..eaea98d 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "repository": "pillarjs/router", "dependencies": { "array-flatten": "2.1.1", - "debug": "2.6.9", + "debug": "3.1.0", "methods": "~1.1.2", "parseurl": "~1.3.2", "path-to-regexp": "0.1.7", From 4d786f0050fcec2c0804e591836ed0b3b2afccc5 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 19 Jul 2018 15:06:32 -0400 Subject: [PATCH 003/207] build: supertest@1.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eaea98d..1042a5c 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "finalhandler": "1.1.1", "istanbul": "0.4.5", "mocha": "2.5.3", - "supertest": "1.1.0" + "supertest": "1.2.0" }, "files": [ "lib/", From dff0a94b094916dab57fc0c0cceda0f3f7dc6a9f Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 19 Jul 2018 15:06:52 -0400 Subject: [PATCH 004/207] build: mocha@3.5.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1042a5c..1165e22 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.0-beta.6", "finalhandler": "1.1.1", "istanbul": "0.4.5", - "mocha": "2.5.3", + "mocha": "3.5.3", "supertest": "1.2.0" }, "files": [ From f0c4c7097bb639bcad4d44c19701bad826584e49 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 19 Jul 2018 15:08:22 -0400 Subject: [PATCH 005/207] build: use nyc for test coverage --- .gitignore | 1 + .travis.yml | 7 +++---- package.json | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 0fa6951..f15b98e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.nyc_output/ coverage/ node_modules/ npm-debug.log diff --git a/.travis.yml b/.travis.yml index bcfa6aa..c92003f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,9 +25,8 @@ before_install: - "test ! -d node_modules || npm prune" - "test ! -d node_modules || npm rebuild" script: - # Run test script, depending on istanbul install - - "test ! -z $(npm -ps ls istanbul) || npm test" - - "test -z $(npm -ps ls istanbul) || npm run-script test-travis" + # Run test script, then lint depending on eslint install + - "npm run-script test-travis" - "test -z $(npm -ps ls eslint) || npm run-script lint" after_script: - - "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" + - "test -d .nyc_output && npm install coveralls@2 && nyc report --reporter=text-lcov | coveralls" diff --git a/package.json b/package.json index 1165e22..cdf0348 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "eslint": "3.19.0", "eslint-plugin-markdown": "1.0.0-beta.6", "finalhandler": "1.1.1", - "istanbul": "0.4.5", "mocha": "3.5.3", + "nyc": "10.3.2", "supertest": "1.2.0" }, "files": [ @@ -39,7 +39,7 @@ "scripts": { "lint": "eslint --plugin markdown --ext js,md .", "test": "mocha --reporter spec --bail --check-leaks test/", - "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", - "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/" + "test-cov": "nyc --reporter=text npm test", + "test-travis": "nyc --reporter=html --reporter=text npm test" } } From d2bce0c09d424ea89e77cef7743e12f411ed94f7 Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Sat, 13 Aug 2016 17:39:26 -0700 Subject: [PATCH 006/207] Add basic support for returned, rejected Promises closes #47 --- HISTORY.md | 2 + README.md | 5 ++ lib/layer.js | 34 +++++++++++- test/route.js | 137 +++++++++++++++++++++++++++++++++++++++++++++++++ test/router.js | 114 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 290 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 7a388b2..d9f6e64 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,8 @@ 2.x === + * Add basic support for returned, rejected Promises + - Rejected Promises from middleware functions `next(error)` * Drop support for Node.js below 0.10 * deps: debug@3.1.0 - Add `DEBUG_HIDE_DATE` environment variable diff --git a/README.md b/README.md index 15d9b66..6c5bddf 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,11 @@ format is with three parameters - "req", "res" and "next". - `res` - This is a [HTTP server response](https://nodejs.org/api/http.html#http_class_http_serverresponse) instance. - `next` - Calling this function that tells `router` to proceed to the next matching middleware or method handler. It accepts an error as the first argument. +The function can optionally return a `Promise` object. If a `Promise` object +is returned from the function, the router will attach an `onRejected` callback +using `.then`. If the promise is rejected, `next` will be called with the +rejected value, or an error if the value is falsy. + Middleware and method handlers can also be defined with four arguments. When the function has four parameters defined, the first argument is an error and subsequent arguments remain, becoming - "err", "req", "res", "next". These diff --git a/lib/layer.js b/lib/layer.js index 60a737f..c012165 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -66,7 +66,15 @@ Layer.prototype.handle_error = function handle_error(error, req, res, next) { } try { - fn(error, req, res, next) + // invoke function + var ret = fn(error, req, res, next) + + // wait for returned promise + if (isPromise(ret)) { + ret.then(null, function (error) { + next(error || new Error('Rejected promise')) + }) + } } catch (err) { next(err) } @@ -90,7 +98,15 @@ Layer.prototype.handle_request = function handle(req, res, next) { } try { - fn(req, res, next) + // invoke function + var ret = fn(req, res, next) + + // wait for returned promise + if (isPromise(ret)) { + ret.then(null, function (error) { + next(error || new Error('Rejected promise')) + }) + } } catch (err) { next(err) } @@ -178,3 +194,17 @@ function decode_param(val){ throw err } } + +/** + * Returns true if the val is a Promise. + * + * @param {*} val + * @return {boolean} + * @private + */ + +function isPromise (val) { + return val && + typeof val === 'object' && + typeof val.then === 'function' +} diff --git a/test/route.js b/test/route.js index 47c8ff5..d680272 100644 --- a/test/route.js +++ b/test/route.js @@ -11,6 +11,8 @@ var request = utils.request var shouldHitHandle = utils.shouldHitHandle var shouldNotHitHandle = utils.shouldNotHitHandle +var describePromises = global.Promise ? describe : describe.skip + describe('Router', function () { describe('.route(path)', function () { it('should return a new route', function () { @@ -467,6 +469,141 @@ describe('Router', function () { }) }) + describePromises('promise support', function () { + it('should pass rejected promise value', function (done) { + var router = new Router() + var route = router.route('/foo') + var server = createServer(router) + + route.all(function createError (req, res, next) { + return Promise.reject(new Error('boom!')) + }) + + route.all(helloWorld) + + route.all(function handleError (err, req, res, next) { + res.statusCode = 500 + res.end('caught: ' + err.message) + }) + + request(server) + .get('/foo') + .expect(500, 'caught: boom!', done) + }) + + it('should pass rejected promise without value', function (done) { + var router = new Router() + var route = router.route('/foo') + var server = createServer(router) + + route.all(function createError (req, res, next) { + return Promise.reject() + }) + + route.all(helloWorld) + + route.all(function handleError (err, req, res, next) { + res.statusCode = 500 + res.end('caught: ' + err.message) + }) + + request(server) + .get('/foo') + .expect(500, 'caught: Rejected promise', done) + }) + + it('should ignore resolved promise', function (done) { + var router = new Router() + var route = router.route('/foo') + var server = createServer(router) + + route.all(function createError (req, res, next) { + saw(req, res) + return Promise.resolve('foo') + }) + + route.all(function () { + done(new Error('Unexpected route invoke')) + }) + + request(server) + .get('/foo') + .expect(200, 'saw GET /foo', done) + }) + + describe('error handling', function () { + it('should pass rejected promise value', function (done) { + var router = new Router() + var route = router.route('/foo') + var server = createServer(router) + + route.all(function createError (req, res, next) { + return Promise.reject(new Error('boom!')) + }) + + route.all(function handleError (err, req, res, next) { + return Promise.reject(new Error('caught: ' + err.message)) + }) + + route.all(function handleError (err, req, res, next) { + res.statusCode = 500 + res.end('caught again: ' + err.message) + }) + + request(server) + .get('/foo') + .expect(500, 'caught again: caught: boom!', done) + }) + + it('should pass rejected promise without value', function (done) { + var router = new Router() + var route = router.route('/foo') + var server = createServer(router) + + route.all(function createError (req, res, next) { + return Promise.reject(new Error('boom!')) + }) + + route.all(function handleError (err, req, res, next) { + return Promise.reject() + }) + + route.all(function handleError (err, req, res, next) { + res.statusCode = 500 + res.end('caught again: ' + err.message) + }) + + request(server) + .get('/foo') + .expect(500, 'caught again: Rejected promise', done) + }) + + it('should ignore resolved promise', function (done) { + var router = new Router() + var route = router.route('/foo') + var server = createServer(router) + + route.all(function createError (req, res, next) { + return Promise.reject(new Error('boom!')) + }) + + route.all(function handleError (err, req, res, next) { + res.statusCode = 500 + res.end('caught: ' + err.message) + return Promise.resolve('foo') + }) + + route.all(function () { + done(new Error('Unexpected route invoke')) + }) + + request(server) + .get('/foo') + .expect(500, 'caught: boom!', done) + }) + }) + }) + describe('path', function () { describe('using ":name"', function () { it('should name a capture group', function (done) { diff --git a/test/router.js b/test/router.js index ea3d73c..0bb89a4 100644 --- a/test/router.js +++ b/test/router.js @@ -12,6 +12,8 @@ var request = utils.request var shouldHitHandle = utils.shouldHitHandle var shouldNotHitHandle = utils.shouldNotHitHandle +var describePromises = global.Promise ? describe : describe.skip + describe('Router', function () { it('should return a function', function () { assert.equal(typeof Router(), 'function') @@ -690,6 +692,118 @@ describe('Router', function () { }) }) + describePromises('promise support', function () { + it('should pass rejected promise value', function (done) { + var router = new Router() + var server = createServer(router) + + router.use(function createError (req, res, next) { + return Promise.reject(new Error('boom!')) + }) + + router.use(sawError) + + request(server) + .get('/') + .expect(200, 'saw Error: boom!', done) + }) + + it('should pass rejected promise without value', function (done) { + var router = new Router() + var server = createServer(router) + + router.use(function createError (req, res, next) { + return Promise.reject() + }) + + router.use(sawError) + + request(server) + .get('/') + .expect(200, 'saw Error: Rejected promise', done) + }) + + it('should ignore resolved promise', function (done) { + var router = new Router() + var server = createServer(router) + + router.use(function createError (req, res, next) { + saw(req, res) + return Promise.resolve('foo') + }) + + router.use(function () { + done(new Error('Unexpected middleware invoke')) + }) + + request(server) + .get('/foo') + .expect(200, 'saw GET /foo', done) + }) + + describe('error handling', function () { + it('should pass rejected promise value', function (done) { + var router = new Router() + var server = createServer(router) + + router.use(function createError (req, res, next) { + return Promise.reject(new Error('boom!')) + }) + + router.use(function handleError (err, req, res, next) { + return Promise.reject(new Error('caught: ' + err.message)) + }) + + router.use(sawError) + + request(server) + .get('/') + .expect(200, 'saw Error: caught: boom!', done) + }) + + it('should pass rejected promise without value', function (done) { + var router = new Router() + var server = createServer(router) + + router.use(function createError (req, res, next) { + return Promise.reject() + }) + + router.use(function handleError (err, req, res, next) { + return Promise.reject(new Error('caught: ' + err.message)) + }) + + router.use(sawError) + + request(server) + .get('/') + .expect(200, 'saw Error: caught: Rejected promise', done) + }) + + it('should ignore resolved promise', function (done) { + var router = new Router() + var server = createServer(router) + + router.use(function createError (req, res, next) { + return Promise.reject(new Error('boom!')) + }) + + router.use(function handleError (err, req, res, next) { + sawError(err, req, res, next) + return Promise.resolve('foo') + }) + + router.use(function () { + done(new Error('Unexpected middleware invoke')) + }) + + request(server) + .get('/foo') + .expect(200, 'saw Error: boom!', done) + }) + }) + }) + describe('req.baseUrl', function () { it('should be empty', function (done) { var router = new Router() From dbaa56ece659bb4c03f5e9f58826b82254ef9b60 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 27 Jul 2018 12:37:19 -0400 Subject: [PATCH 007/207] 2.0.0-alpha.1 --- HISTORY.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index d9f6e64..72ac292 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,5 @@ -2.x -=== +2.0.0-alpha.1 / 2018-07-27 +========================== * Add basic support for returned, rejected Promises - Rejected Promises from middleware functions `next(error)` diff --git a/package.json b/package.json index cdf0348..41328ab 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "router", "description": "Simple middleware-style router", - "version": "1.3.3", + "version": "2.0.0-alpha.1", "author": "Douglas Christopher Wilson ", "contributors": [ "Blake Embrey " From a947e3616b2445bdfe12c9d9a9eececf0bdbfead Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 1 Jun 2019 22:09:10 -0400 Subject: [PATCH 008/207] deps: parseurl@~1.3.3 --- HISTORY.md | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 408414c..bcd5084 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ unreleased ========== * deps: array-flatten@2.1.2 + * deps: parseurl@~1.3.3 * deps: setprototypeof@1.1.1 1.3.3 / 2018-07-06 diff --git a/package.json b/package.json index 8b25b42..c712785 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "array-flatten": "2.1.2", "debug": "2.6.9", "methods": "~1.1.2", - "parseurl": "~1.3.2", + "parseurl": "~1.3.3", "path-to-regexp": "0.1.7", "setprototypeof": "1.1.1", "utils-merge": "1.0.1" From a079f89a26ac56e90aa122bef47e5d25e210e204 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 1 Jun 2019 22:14:58 -0400 Subject: [PATCH 009/207] build: Node.js@10.16 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 719be7a..2a28924 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ node_js: - "7.10" - "8.16" - "9.11" - - "10.15" + - "10.16" - "11.15" sudo: false cache: From 92bb6b33c3812537440b0d75a9f5f215d3cf4611 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 28 Jun 2019 19:44:40 -0400 Subject: [PATCH 010/207] build: restructure Travis CI build steps --- .travis.yml | 53 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2a28924..05d9b61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,18 +19,49 @@ cache: directories: - node_modules before_install: - # Skip updating shrinkwrap / lock - - "npm config set shrinkwrap false" + # Configure npm + - | + # Skip updating shrinkwrap / lock + npm config set shrinkwrap false # Setup Node.js version-specific dependencies - - "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul" - - "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev eslint eslint-plugin-markdown" + - | + # istanbul for coverage + # - remove on Node.js < 0.10 + if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -eq 0 && "$(cut -d. -f2 <<< "$TRAVIS_NODE_VERSION")" -lt 10 ]]; then + npm rm --silent --save-dev istanbul + fi + - | + # eslint for linting + # - remove on Node.js < 4 + if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 4 ]]; then + node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ + grep -E '^eslint(-|$)' | \ + xargs npm rm --silent --save-dev + fi # Update Node.js modules - - "test ! -d node_modules || npm prune" - - "test ! -d node_modules || npm rebuild" + - | + # Prune and rebuild node_modules + if [[ -d node_modules ]]; then + npm prune + npm rebuild + fi script: - # Run test script, depending on istanbul install - - "test ! -z $(npm -ps ls istanbul) || npm test" - - "test -z $(npm -ps ls istanbul) || npm run-script test-travis" - - "test -z $(npm -ps ls eslint) || npm run-script lint" + # Run test script + - | + if npm -ps ls istanbul | grep -q istanbul; then + npm run test-travis + else + npm run test + fi + # Run linting + - | + if npm -ps ls eslint | grep -q eslint; then + npm run lint + fi after_script: - - "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" + # Upload coverage to coveralls + - | + if [[ -f ./coverage/lcov.info ]]; then + npm install --save-dev coveralls@2 + coveralls < ./coverage/lcov.info + fi From b1fdb5d7176c8fd249829e6bad77f1683f5addde Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 10 Jul 2019 19:22:42 -0400 Subject: [PATCH 011/207] build: mocha@6.1.4 --- .travis.yml | 12 ++++++++++++ package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 05d9b61..d022232 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,6 +38,18 @@ before_install: grep -E '^eslint(-|$)' | \ xargs npm rm --silent --save-dev fi + - | + # mocha for testing + # - use 2.x for Node.js < 0.10 + # - use 3.x for Node.js < 4 + # - use 5.x for Node.js < 6 + if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -eq 0 && "$(cut -d. -f2 <<< "$TRAVIS_NODE_VERSION")" -lt 10 ]]; then + npm install --save-dev mocha@2.5.3 + elif [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 4 ]]; then + npm install --save-dev mocha@3.5.3 + elif [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then + npm install --save-dev mocha@5.2.0 + fi # Update Node.js modules - | # Prune and rebuild node_modules diff --git a/package.json b/package.json index c712785..0a68b7f 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.0-beta.6", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "2.5.3", + "mocha": "6.1.4", "supertest": "1.1.0" }, "files": [ From 4fed5377575883d50ccdf3d5b51abd79e389d49f Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 11 Jul 2019 01:22:39 -0400 Subject: [PATCH 012/207] build: supertest@3.4.2 --- .travis.yml | 10 ++++ package.json | 3 +- test/route.js | 46 +++++++++++------- test/router.js | 109 ++++++++++++++++++++++++++---------------- test/support/utils.js | 19 ++++++++ 5 files changed, 126 insertions(+), 61 deletions(-) diff --git a/.travis.yml b/.travis.yml index d022232..bdb8e46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,6 +50,16 @@ before_install: elif [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then npm install --save-dev mocha@5.2.0 fi + - | + # supertest for http calls + # - use 1.1.0 for Node.js < 0.10 + # - use 2.0.0 for Node.js < 4 + # - use 3.4.2 for Node.js < 6 + if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -eq 0 && "$(cut -d. -f2 <<< "$TRAVIS_NODE_VERSION")" -lt 10 ]]; then + npm install --save-dev supertest@1.1.0 + elif [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 4 ]]; then + npm install --save-dev supertest@2.0.0 + fi # Update Node.js modules - | # Prune and rebuild node_modules diff --git a/package.json b/package.json index 0a68b7f..694d705 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "finalhandler": "1.1.2", "istanbul": "0.4.5", "mocha": "6.1.4", - "supertest": "1.1.0" + "safe-buffer": "5.2.0", + "supertest": "3.4.2" }, "files": [ "lib/", diff --git a/test/route.js b/test/route.js index 47c8ff5..fc121e4 100644 --- a/test/route.js +++ b/test/route.js @@ -1,5 +1,6 @@ var after = require('after') +var Buffer = require('safe-buffer').Buffer var methods = require('methods') var Router = require('..') var utils = require('./support/utils') @@ -8,7 +9,9 @@ var assert = utils.assert var createHitHandle = utils.createHitHandle var createServer = utils.createServer var request = utils.request +var shouldHaveBody = utils.shouldHaveBody var shouldHitHandle = utils.shouldHitHandle +var shouldNotHaveBody = utils.shouldNotHaveBody var shouldNotHitHandle = utils.shouldNotHitHandle describe('Router', function () { @@ -191,8 +194,8 @@ describe('Router', function () { } var body = method !== 'head' - ? 'hello, world' - : '' + ? shouldHaveBody(Buffer.from('hello, world')) + : shouldNotHaveBody() describe('.' + method + '(...fn)', function () { it('should respond to a ' + method.toUpperCase() + ' request', function (done) { @@ -203,8 +206,10 @@ describe('Router', function () { route[method](helloWorld) request(server) - [method]('/') - .expect(200, body, done) + [method]('/') + .expect(200) + .expect(body) + .end(done) }) it('should reject no arguments', function () { @@ -233,10 +238,12 @@ describe('Router', function () { route[method](createHitHandle(1), createHitHandle(2), helloWorld) request(server) - [method]('/foo') - .expect('x-fn-1', 'hit') - .expect('x-fn-2', 'hit') - .expect(200, body, done) + [method]('/foo') + .expect(200) + .expect('x-fn-1', 'hit') + .expect('x-fn-2', 'hit') + .expect(body) + .end(done) }) it('should accept single array of handlers', function (done) { @@ -246,11 +253,12 @@ describe('Router', function () { route[method]([createHitHandle(1), createHitHandle(2), helloWorld]) - request(server) - [method]('/foo') - .expect('x-fn-1', 'hit') - .expect('x-fn-2', 'hit') - .expect(200, body, done) + request(server)[method]('/foo') + .expect(200) + .expect('x-fn-1', 'hit') + .expect('x-fn-2', 'hit') + .expect(body) + .end(done) }) it('should accept nested arrays of handlers', function (done) { @@ -261,11 +269,13 @@ describe('Router', function () { route[method]([[createHitHandle(1), createHitHandle(2)], createHitHandle(3)], helloWorld) request(server) - [method]('/foo') - .expect('x-fn-1', 'hit') - .expect('x-fn-2', 'hit') - .expect('x-fn-3', 'hit') - .expect(200, body, done) + [method]('/foo') + .expect(200) + .expect('x-fn-1', 'hit') + .expect('x-fn-2', 'hit') + .expect('x-fn-3', 'hit') + .expect(body) + .end(done) }) }) }) diff --git a/test/router.js b/test/router.js index ea3d73c..c8daed5 100644 --- a/test/router.js +++ b/test/router.js @@ -1,5 +1,6 @@ var after = require('after') +var Buffer = require('safe-buffer').Buffer var methods = require('methods') var Router = require('..') var utils = require('./support/utils') @@ -9,7 +10,9 @@ var createHitHandle = utils.createHitHandle var createServer = utils.createServer var rawrequest = utils.rawrequest var request = utils.request +var shouldHaveBody = utils.shouldHaveBody var shouldHitHandle = utils.shouldHitHandle +var shouldNotHaveBody = utils.shouldNotHaveBody var shouldNotHitHandle = utils.shouldNotHitHandle describe('Router', function () { @@ -51,12 +54,14 @@ describe('Router', function () { } var body = method !== 'head' - ? 'hello, world' - : '' + ? shouldHaveBody(Buffer.from('hello, world')) + : shouldNotHaveBody() request(server) - [method]('/') - .expect(200, body, cb) + [method]('/') + .expect(200) + .expect(body) + .end(cb) }) }) @@ -259,8 +264,8 @@ describe('Router', function () { } var body = method !== 'head' - ? 'hello, world' - : '' + ? shouldHaveBody(Buffer.from('hello, world')) + : shouldNotHaveBody() describe('.' + method + '(path, ...fn)', function () { it('should be chainable', function () { @@ -275,8 +280,10 @@ describe('Router', function () { router[method]('/', helloWorld) request(server) - [method]('/') - .expect(200, body, done) + [method]('/') + .expect(200) + .expect(body) + .end(done) }) it('should reject invalid fn', function () { @@ -292,19 +299,24 @@ describe('Router', function () { router[method](['/foo', '/bar'], createHitHandle(1), helloWorld) request(server) - [method]('/') - .expect(shouldNotHitHandle(1)) - .expect(404, cb) + [method]('/') + .expect(404) + .expect(shouldNotHitHandle(1)) + .end(cb) request(server) - [method]('/foo') - .expect(shouldHitHandle(1)) - .expect(200, body, cb) + [method]('/foo') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(body) + .end(cb) request(server) - [method]('/bar') - .expect(shouldHitHandle(1)) - .expect(200, body, cb) + [method]('/bar') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(body) + .end(cb) }) it('should support regexp path', function (done) { @@ -315,19 +327,24 @@ describe('Router', function () { router[method](/^\/[a-z]oo$/, createHitHandle(1), helloWorld) request(server) - [method]('/') - .expect(shouldNotHitHandle(1)) - .expect(404, cb) + [method]('/') + .expect(404) + .expect(shouldNotHitHandle(1)) + .end(cb) request(server) - [method]('/foo') - .expect(shouldHitHandle(1)) - .expect(200, body, cb) + [method]('/foo') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(body) + .end(cb) request(server) - [method]('/zoo') - .expect(shouldHitHandle(1)) - .expect(200, body, cb) + [method]('/zoo') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(body) + .end(cb) }) it('should support parameterized path', function (done) { @@ -338,24 +355,30 @@ describe('Router', function () { router[method]('/:thing', createHitHandle(1), helloWorld) request(server) - [method]('/') - .expect(shouldNotHitHandle(1)) - .expect(404, cb) + [method]('/') + .expect(404) + .expect(shouldNotHitHandle(1)) + .end(cb) request(server) - [method]('/foo') - .expect(shouldHitHandle(1)) - .expect(200, body, cb) + [method]('/foo') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(body) + .end(cb) request(server) - [method]('/bar') - .expect(shouldHitHandle(1)) - .expect(200, body, cb) + [method]('/bar') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(body) + .end(cb) request(server) - [method]('/foo/bar') - .expect(shouldNotHitHandle(1)) - .expect(404, cb) + [method]('/foo/bar') + .expect(404) + .expect(shouldNotHitHandle(1)) + .end(cb) }) it('should accept multiple arguments', function (done) { @@ -365,10 +388,12 @@ describe('Router', function () { router[method]('/', createHitHandle(1), createHitHandle(2), helloWorld) request(server) - [method]('/') - .expect(shouldHitHandle(1)) - .expect(shouldHitHandle(2)) - .expect(200, body, done) + [method]('/') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(shouldHitHandle(2)) + .expect(body) + .end(done) }) describe('req.baseUrl', function () { diff --git a/test/support/utils.js b/test/support/utils.js index 8841e41..56cfe94 100644 --- a/test/support/utils.js +++ b/test/support/utils.js @@ -1,5 +1,6 @@ var assert = require('assert') +var Buffer = require('safe-buffer').Buffer var finalhandler = require('finalhandler') var http = require('http') var methods = require('methods') @@ -10,6 +11,8 @@ exports.createHitHandle = createHitHandle exports.createServer = createServer exports.rawrequest = rawrequest exports.request = request +exports.shouldHaveBody = shouldHaveBody +exports.shouldNotHaveBody = shouldNotHaveBody exports.shouldHitHandle = shouldHitHandle exports.shouldNotHitHandle = shouldNotHitHandle @@ -104,6 +107,16 @@ function rawrequest(server) { return _test } +function shouldHaveBody (buf) { + return function (res) { + var body = !Buffer.isBuffer(res.body) + ? Buffer.from(res.text) + : res.body + assert.ok(body, 'response has body') + assert.strictEqual(body.toString('hex'), buf.toString('hex')) + } +} + function shouldHitHandle(num) { var header = 'x-fn-' + String(num) return function (res) { @@ -111,6 +124,12 @@ function shouldHitHandle(num) { } } +function shouldNotHaveBody () { + return function (res) { + assert.ok(res.text === '' || res.text === undefined) + } +} + function shouldNotHitHandle(num) { return shouldNotHaveHeader('x-fn-' + String(num)) } From 8c38e9f0ae08d21d86864bb25d8ac69c38646d78 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 23 Jan 2020 19:02:37 -0500 Subject: [PATCH 013/207] build: Node.js@8.17 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bdb8e46..31edd70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ node_js: - "5.12" - "6.17" - "7.10" - - "8.16" + - "8.17" - "9.11" - "10.16" - "11.15" From a3a2d381a8e6ebceedf9982121e73cc6315d04bc Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 23 Jan 2020 19:09:57 -0500 Subject: [PATCH 014/207] build: Node.js@10.18 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 31edd70..f9ae5f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ node_js: - "7.10" - "8.17" - "9.11" - - "10.16" + - "10.18" - "11.15" sudo: false cache: From 62455fae372b8606d1bc5b5e92e66736b312a598 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 23 Jan 2020 19:24:14 -0500 Subject: [PATCH 015/207] build: simplify & speed up logic in Travis CI build steps --- .travis.yml | 86 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/.travis.yml b/.travis.yml index f9ae5f4..b6cc662 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,46 +19,61 @@ cache: directories: - node_modules before_install: + - | + # Setup utility functions + function node_version_lt () { + [[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v "${1}")" ]] + } + function npm_module_installed () { + npm -lsp ls | grep -Fq "$(pwd)/node_modules/${1}:${1}@" + } + function npm_remove_module_re () { + node -e ' + fs = require("fs"); + p = JSON.parse(fs.readFileSync("package.json", "utf8")); + r = RegExp(process.argv[1]); + for (k in p.devDependencies) { + if (r.test(k)) delete p.devDependencies[k]; + } + fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n"); + ' "$@" + } + function npm_use_module () { + node -e ' + fs = require("fs"); + p = JSON.parse(fs.readFileSync("package.json", "utf8")); + p.devDependencies[process.argv[1]] = process.argv[2]; + fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n"); + ' "$@" + } + function v () { + tr '.' '\n' <<< "${1}" \ + | awk '{ printf "%03d", $0 }' \ + | sed 's/^0*//' + } # Configure npm - | # Skip updating shrinkwrap / lock npm config set shrinkwrap false # Setup Node.js version-specific dependencies - | - # istanbul for coverage - # - remove on Node.js < 0.10 - if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -eq 0 && "$(cut -d. -f2 <<< "$TRAVIS_NODE_VERSION")" -lt 10 ]]; then - npm rm --silent --save-dev istanbul + # Configure eslint for linting + if node_version_lt '4.0'; then npm_remove_module_re '^eslint(-|$)' fi - | - # eslint for linting - # - remove on Node.js < 4 - if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 4 ]]; then - node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ - grep -E '^eslint(-|$)' | \ - xargs npm rm --silent --save-dev + # Configure istanbul for coverage + if node_version_lt '0.10'; then npm_remove_module_re '^istanbul$' fi - | - # mocha for testing - # - use 2.x for Node.js < 0.10 - # - use 3.x for Node.js < 4 - # - use 5.x for Node.js < 6 - if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -eq 0 && "$(cut -d. -f2 <<< "$TRAVIS_NODE_VERSION")" -lt 10 ]]; then - npm install --save-dev mocha@2.5.3 - elif [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 4 ]]; then - npm install --save-dev mocha@3.5.3 - elif [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 6 ]]; then - npm install --save-dev mocha@5.2.0 + # Configure mocha for testing + if node_version_lt '0.10'; then npm_use_module 'mocha' '2.5.3' + elif node_version_lt '4.0' ; then npm_use_module 'mocha' '3.5.3' + elif node_version_lt '6.0' ; then npm_use_module 'mocha' '5.2.0' fi - | - # supertest for http calls - # - use 1.1.0 for Node.js < 0.10 - # - use 2.0.0 for Node.js < 4 - # - use 3.4.2 for Node.js < 6 - if [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -eq 0 && "$(cut -d. -f2 <<< "$TRAVIS_NODE_VERSION")" -lt 10 ]]; then - npm install --save-dev supertest@1.1.0 - elif [[ "$(cut -d. -f1 <<< "$TRAVIS_NODE_VERSION")" -lt 4 ]]; then - npm install --save-dev supertest@2.0.0 + # Configure supertest for http calls + if node_version_lt '0.10'; then npm_use_module 'supertest' '1.1.0' + elif node_version_lt '4.0' ; then npm_use_module 'supertest' '2.0.0' fi # Update Node.js modules - | @@ -68,20 +83,17 @@ before_install: npm rebuild fi script: - # Run test script + # Run test script, depending on istanbul install - | - if npm -ps ls istanbul | grep -q istanbul; then - npm run test-travis - else - npm run test + if npm_module_installed 'istanbul'; then npm run-script test-travis + else npm test fi - # Run linting + # Run linting, depending on eslint install - | - if npm -ps ls eslint | grep -q eslint; then - npm run lint + if npm_module_installed 'eslint'; then npm run-script lint fi after_script: - # Upload coverage to coveralls + # Upload coverage to coveralls if exists - | if [[ -f ./coverage/lcov.info ]]; then npm install --save-dev coveralls@2 From 1813f0c4a29a1dc3068286784f6a53e898263fa1 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Tue, 5 Mar 2019 22:17:16 +0100 Subject: [PATCH 016/207] tests: bump timeout on a long-running test closes #79 --- test/router.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/router.js b/test/router.js index c8daed5..8b49dab 100644 --- a/test/router.js +++ b/test/router.js @@ -130,6 +130,8 @@ describe('Router', function () { }) it('should not stack overflow with many registered routes', function (done) { + this.timeout(5000) // long-running test + var router = new Router() var server = createServer(router) From a22f10eebebc242011556ba89817d95093e68a9e Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Wed, 17 Jul 2019 21:58:24 -0700 Subject: [PATCH 017/207] deps: setprototypeof@1.2.0 closes #81 --- HISTORY.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index bcd5084..55f4ce1 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,7 +3,7 @@ unreleased * deps: array-flatten@2.1.2 * deps: parseurl@~1.3.3 - * deps: setprototypeof@1.1.1 + * deps: setprototypeof@1.2.0 1.3.3 / 2018-07-06 ================== diff --git a/package.json b/package.json index 694d705..40bbd43 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "methods": "~1.1.2", "parseurl": "~1.3.3", "path-to-regexp": "0.1.7", - "setprototypeof": "1.1.1", + "setprototypeof": "1.2.0", "utils-merge": "1.0.1" }, "devDependencies": { From e5a42fedcf860ef3ce13a61a92756efab3209b64 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sun, 5 Jan 2020 09:59:59 -0800 Subject: [PATCH 018/207] build: eslint@6.8.0 closes #84 --- .travis.yml | 2 +- README.md | 16 +- package.json | 2 +- test/auto-head.js | 16 +- test/auto-options.js | 32 ++-- test/fqdn-url.js | 22 +-- test/param.js | 70 +++---- test/req.params.js | 50 ++--- test/route.js | 222 ++++++++++----------- test/router.js | 446 +++++++++++++++++++++---------------------- 10 files changed, 439 insertions(+), 439 deletions(-) diff --git a/.travis.yml b/.travis.yml index b6cc662..acf57a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,7 +58,7 @@ before_install: # Setup Node.js version-specific dependencies - | # Configure eslint for linting - if node_version_lt '4.0'; then npm_remove_module_re '^eslint(-|$)' + if node_version_lt '8.0'; then npm_remove_module_re '^eslint(-|$)' fi - | # Configure istanbul for coverage diff --git a/README.md b/README.md index 15d9b66..d346090 100644 --- a/README.md +++ b/README.md @@ -175,14 +175,14 @@ rather than responding. ```js router.route('/') -.all(function (req, res, next) { - next() -}) -.all(check_something) -.get(function (req, res) { - res.setHeader('Content-Type', 'text/plain; charset=utf-8') - res.end('Hello World!') -}) + .all(function (req, res, next) { + next() + }) + .all(check_something) + .get(function (req, res) { + res.setHeader('Content-Type', 'text/plain; charset=utf-8') + res.end('Hello World!') + }) ``` ## Middleware diff --git a/package.json b/package.json index 40bbd43..eeb34d8 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "3.19.0", + "eslint": "6.8.0", "eslint-plugin-markdown": "1.0.0-beta.6", "finalhandler": "1.1.2", "istanbul": "0.4.5", diff --git a/test/auto-head.js b/test/auto-head.js index f64a0fa..bb63145 100644 --- a/test/auto-head.js +++ b/test/auto-head.js @@ -13,10 +13,10 @@ describe('HEAD', function () { router.get('/users', sethit(1), saw) request(server) - .head('/users') - .expect('Content-Type', 'text/plain') - .expect('x-fn-1', 'hit') - .expect(200, done) + .head('/users') + .expect('Content-Type', 'text/plain') + .expect('x-fn-1', 'hit') + .expect(200, done) }) it('should invoke head if prior to get', function (done) { @@ -27,10 +27,10 @@ describe('HEAD', function () { router.get('/users', sethit(2), saw) request(server) - .head('/users') - .expect('Content-Type', 'text/plain') - .expect('x-fn-1', 'hit') - .expect(200, done) + .head('/users') + .expect('Content-Type', 'text/plain') + .expect('x-fn-1', 'hit') + .expect(200, done) }) }) diff --git a/test/auto-options.js b/test/auto-options.js index cd7a0b4..ac90959 100644 --- a/test/auto-options.js +++ b/test/auto-options.js @@ -16,9 +16,9 @@ describe('OPTIONS', function () { router.put('/users', saw) request(server) - .options('/users') - .expect('Allow', 'GET, HEAD, POST, PUT') - .expect(200, 'GET, HEAD, POST, PUT', done) + .options('/users') + .expect('Allow', 'GET, HEAD, POST, PUT') + .expect(200, 'GET, HEAD, POST, PUT', done) }) it('should not contain methods multiple times', function (done) { @@ -31,9 +31,9 @@ describe('OPTIONS', function () { router.get('/users', saw) request(server) - .options('/users') - .expect('GET, HEAD, PUT') - .expect('Allow', 'GET, HEAD, PUT', done) + .options('/users') + .expect('GET, HEAD, PUT') + .expect('Allow', 'GET, HEAD, PUT', done) }) it('should not include "all" routes', function (done) { @@ -46,10 +46,10 @@ describe('OPTIONS', function () { router.all('/users', sethit(1)) request(server) - .options('/users') - .expect('x-fn-1', 'hit') - .expect('Allow', 'GET, HEAD, PUT') - .expect(200, 'GET, HEAD, PUT', done) + .options('/users') + .expect('x-fn-1', 'hit') + .expect('Allow', 'GET, HEAD, PUT') + .expect(200, 'GET, HEAD, PUT', done) }) it('should not respond if no matching path', function (done) { @@ -59,8 +59,8 @@ describe('OPTIONS', function () { router.get('/users', saw) request(server) - .options('/') - .expect(404, done) + .options('/') + .expect(404, done) }) it('should do nothing with explicit options route', function (done) { @@ -71,8 +71,8 @@ describe('OPTIONS', function () { router.options('/users', saw) request(server) - .options('/users') - .expect(200, 'saw OPTIONS /users', done) + .options('/users') + .expect(200, 'saw OPTIONS /users', done) }) describe('when error occurs in respone handler', function () { @@ -88,8 +88,8 @@ describe('OPTIONS', function () { router.get('/users', saw) request(server) - .options('/users') - .expect(200, 'true', done) + .options('/users') + .expect(200, 'true', done) }) }) }) diff --git a/test/fqdn-url.js b/test/fqdn-url.js index 5411500..7fc0b71 100644 --- a/test/fqdn-url.js +++ b/test/fqdn-url.js @@ -13,8 +13,8 @@ describe('FQDN url', function () { router.use(saw) rawrequest(server) - .get('http://example.com/foo') - .expect(200, 'saw GET http://example.com/foo', done) + .get('http://example.com/foo') + .expect(200, 'saw GET http://example.com/foo', done) }) it('should strip/restore FQDN req.url', function (done) { @@ -25,9 +25,9 @@ describe('FQDN url', function () { router.use(saw) rawrequest(server) - .get('http://example.com/blog/post/1') - .expect('x-saw-1', 'GET http://example.com/post/1') - .expect(200, 'saw GET http://example.com/blog/post/1', done) + .get('http://example.com/blog/post/1') + .expect('x-saw-1', 'GET http://example.com/post/1') + .expect(200, 'saw GET http://example.com/blog/post/1', done) }) it('should ignore FQDN in search', function (done) { @@ -38,9 +38,9 @@ describe('FQDN url', function () { router.use(saw) rawrequest(server) - .get('/proxy?url=http://example.com/blog/post/1') - .expect('x-saw-1', 'GET /?url=http://example.com/blog/post/1') - .expect(200, 'saw GET /proxy?url=http://example.com/blog/post/1', done) + .get('/proxy?url=http://example.com/blog/post/1') + .expect('x-saw-1', 'GET /?url=http://example.com/blog/post/1') + .expect(200, 'saw GET /proxy?url=http://example.com/blog/post/1', done) }) it('should ignore FQDN in path', function (done) { @@ -51,9 +51,9 @@ describe('FQDN url', function () { router.use(saw) rawrequest(server) - .get('/proxy/http://example.com/blog/post/1') - .expect('x-saw-1', 'GET /http://example.com/blog/post/1') - .expect(200, 'saw GET /proxy/http://example.com/blog/post/1', done) + .get('/proxy/http://example.com/blog/post/1') + .expect('x-saw-1', 'GET /http://example.com/blog/post/1') + .expect(200, 'saw GET /proxy/http://example.com/blog/post/1', done) }) }) diff --git a/test/param.js b/test/param.js index e2a5aad..7a31a3c 100644 --- a/test/param.js +++ b/test/param.js @@ -48,12 +48,12 @@ describe('Router', function () { }) request(server) - .get('/user/2') - .expect(200, 'get user 2', cb) + .get('/user/2') + .expect(200, 'get user 2', cb) request(server) - .get('/user/bob') - .expect(200, 'get user NaN', cb) + .get('/user/bob') + .expect(200, 'get user NaN', cb) }) it('should allow chaining', function (done) { @@ -76,8 +76,8 @@ describe('Router', function () { }) request(server) - .get('/user/2') - .expect(200, 'get user 2 (2)', done) + .get('/user/2') + .expect(200, 'get user 2 (2)', done) }) it('should automatically decode path value', function (done) { @@ -95,8 +95,8 @@ describe('Router', function () { }) request(server) - .get('/user/%22bob%2Frobert%22') - .expect('get user "bob/robert"', done) + .get('/user/%22bob%2Frobert%22') + .expect('get user "bob/robert"', done) }) it('should 400 on invalid path value', function (done) { @@ -114,8 +114,8 @@ describe('Router', function () { }) request(server) - .get('/user/%bob') - .expect(400, /URIError: Failed to decode param/, done) + .get('/user/%bob') + .expect(400, /URIError: Failed to decode param/, done) }) it('should only invoke fn when necessary', function (done) { @@ -136,13 +136,13 @@ describe('Router', function () { router.put('/user/:id', saw) request(server) - .get('/user/bob') - .expect(500, /Error: boom/, cb) + .get('/user/bob') + .expect(500, /Error: boom/, cb) request(server) - .put('/user/bob') - .expect('x-id', 'bob') - .expect(200, 'saw PUT /user/bob', cb) + .put('/user/bob') + .expect('x-id', 'bob') + .expect(200, 'saw PUT /user/bob', cb) }) it('should only invoke fn once per request', function (done) { @@ -163,8 +163,8 @@ describe('Router', function () { }) request(server) - .get('/user/bob') - .expect('get user bob 1 times', done) + .get('/user/bob') + .expect('get user bob 1 times', done) }) it('should keep changes to req.params value', function (done) { @@ -187,8 +187,8 @@ describe('Router', function () { }) request(server) - .get('/user/01') - .expect('get user 1 1 times', done) + .get('/user/01') + .expect('get user 1 1 times', done) }) it('should invoke fn if path value differs', function (done) { @@ -210,8 +210,8 @@ describe('Router', function () { }) request(server) - .get('/user/bob') - .expect('get user bob 2 times: user, bob', done) + .get('/user/bob') + .expect('get user bob 2 times: user, bob', done) }) it('should catch exception in fn', function (done) { @@ -228,8 +228,8 @@ describe('Router', function () { }) request(server) - .get('/user/bob') - .expect(500, /Error: boom/, done) + .get('/user/bob') + .expect(500, /Error: boom/, done) }) it('should catch exception in chained fn', function (done) { @@ -250,8 +250,8 @@ describe('Router', function () { }) request(server) - .get('/user/bob') - .expect(500, /Error: boom/, done) + .get('/user/bob') + .expect(500, /Error: boom/, done) }) describe('next("route")', function () { @@ -283,16 +283,16 @@ describe('Router', function () { }) request(server) - .get('/user/2') - .expect(200, 'get user 2', cb) + .get('/user/2') + .expect(200, 'get user 2', cb) request(server) - .get('/user/bob') - .expect(404, cb) + .get('/user/bob') + .expect(404, cb) request(server) - .get('/user/new') - .expect(400, 'cannot get a new user', cb) + .get('/user/new') + .expect(400, 'cannot get a new user', cb) }) it('should invoke fn if path value differs', function (done) { @@ -314,10 +314,10 @@ describe('Router', function () { }) request(server) - .get('/user/bob') - .expect(shouldNotHitHandle(1)) - .expect(shouldHitHandle(2)) - .expect('get user bob 2 times: user, bob', done) + .get('/user/bob') + .expect(shouldNotHitHandle(1)) + .expect(shouldHitHandle(2)) + .expect('get user bob 2 times: user, bob', done) }) }) }) diff --git a/test/req.params.js b/test/req.params.js index c7dbba2..46e5b19 100644 --- a/test/req.params.js +++ b/test/req.params.js @@ -13,8 +13,8 @@ describe('req.params', function () { router.get('/', sawParams) request(server) - .get('/') - .expect(200, '{}', done) + .get('/') + .expect(200, '{}', done) }) it('should not exist outside the router', function (done) { @@ -29,9 +29,9 @@ describe('req.params', function () { router.get('/', hitParams(1)) request(server) - .get('/') - .expect('x-params-1', '{}') - .expect(200, '', done) + .get('/') + .expect('x-params-1', '{}') + .expect(200, '', done) }) it('should overwrite value outside the router', function (done) { @@ -44,8 +44,8 @@ describe('req.params', function () { router.get('/', sawParams) request(server) - .get('/') - .expect(200, '{}', done) + .get('/') + .expect(200, '{}', done) }) it('should restore previous value outside the router', function (done) { @@ -62,9 +62,9 @@ describe('req.params', function () { router.get('/', hitParams(1)) request(server) - .get('/') - .expect('x-params-1', '{}') - .expect(200, '{"foo":"bar"}', done) + .get('/') + .expect('x-params-1', '{}') + .expect(200, '{"foo":"bar"}', done) }) describe('when "mergeParams: true"', function () { @@ -82,9 +82,9 @@ describe('req.params', function () { router.get('/:fizz', hitParams(1)) request(server) - .get('/buzz') - .expect('x-params-1', '{"foo":"bar","fizz":"buzz"}') - .expect(200, '{"foo":"bar"}', done) + .get('/buzz') + .expect('x-params-1', '{"foo":"bar","fizz":"buzz"}') + .expect(200, '{"foo":"bar"}', done) }) it('should ignore non-object outsite object', function (done) { @@ -101,9 +101,9 @@ describe('req.params', function () { router.get('/:fizz', hitParams(1)) request(server) - .get('/buzz') - .expect('x-params-1', '{"fizz":"buzz"}') - .expect(200, '42', done) + .get('/buzz') + .expect('x-params-1', '{"fizz":"buzz"}') + .expect(200, '42', done) }) it('should overwrite outside keys that are the same', function (done) { @@ -120,9 +120,9 @@ describe('req.params', function () { router.get('/:foo', hitParams(1)) request(server) - .get('/buzz') - .expect('x-params-1', '{"foo":"buzz"}') - .expect(200, '{"foo":"bar"}', done) + .get('/buzz') + .expect('x-params-1', '{"foo":"buzz"}') + .expect(200, '{"foo":"bar"}', done) }) describe('with numeric properties in req.params', function () { @@ -140,9 +140,9 @@ describe('req.params', function () { router.get('/*', hitParams(1)) request(server) - .get('/buzz') - .expect('x-params-1', '{"0":"foo","1":"bar","2":"buzz"}') - .expect(200, '{"0":"foo","1":"bar"}', done) + .get('/buzz') + .expect('x-params-1', '{"0":"foo","1":"bar","2":"buzz"}') + .expect(200, '{"0":"foo","1":"bar"}', done) }) it('should merge with same numeric properties', function (done) { @@ -159,9 +159,9 @@ describe('req.params', function () { router.get('/*', hitParams(1)) request(server) - .get('/bar') - .expect('x-params-1', '{"0":"foo","1":"bar"}') - .expect(200, '{"0":"foo"}', done) + .get('/bar') + .expect('x-params-1', '{"0":"foo","1":"bar"}') + .expect(200, '{"0":"foo"}', done) }) }) }) diff --git a/test/route.js b/test/route.js index fc121e4..a88b29f 100644 --- a/test/route.js +++ b/test/route.js @@ -32,16 +32,16 @@ describe('Router', function () { route.post(saw) request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) + .get('/foo') + .expect(200, 'saw GET /foo', cb) request(server) - .post('/foo') - .expect(200, 'saw POST /foo', cb) + .post('/foo') + .expect(200, 'saw POST /foo', cb) request(server) - .put('/foo') - .expect(404, cb) + .put('/foo') + .expect(404, cb) }) it('should stack', function (done) { @@ -57,21 +57,21 @@ describe('Router', function () { router.use(saw) request(server) - .get('/foo') - .expect('x-fn-2', 'hit') - .expect('x-fn-3', 'hit') - .expect(200, 'saw GET /foo', cb) + .get('/foo') + .expect('x-fn-2', 'hit') + .expect('x-fn-3', 'hit') + .expect(200, 'saw GET /foo', cb) request(server) - .post('/foo') - .expect('x-fn-1', 'hit') - .expect('x-fn-2', 'hit') - .expect(200, 'saw POST /foo', cb) + .post('/foo') + .expect('x-fn-1', 'hit') + .expect('x-fn-2', 'hit') + .expect(200, 'saw POST /foo', cb) request(server) - .put('/foo') - .expect('x-fn-2', 'hit') - .expect(200, 'saw PUT /foo', cb) + .put('/foo') + .expect('x-fn-2', 'hit') + .expect(200, 'saw PUT /foo', cb) }) it('should not error on empty route', function (done) { @@ -81,12 +81,12 @@ describe('Router', function () { var server = createServer(router) request(server) - .get('/foo') - .expect(404, cb) + .get('/foo') + .expect(404, cb) request(server) - .head('/foo') - .expect(404, cb) + .head('/foo') + .expect(404, cb) }) it('should not invoke singular error route', function (done) { @@ -99,8 +99,8 @@ describe('Router', function () { }) request(server) - .get('/foo') - .expect(404, done) + .get('/foo') + .expect(404, done) }) describe('.all(...fn)', function () { @@ -131,16 +131,16 @@ describe('Router', function () { route.all(saw) request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) + .get('/foo') + .expect(200, 'saw GET /foo', cb) request(server) - .post('/foo') - .expect(200, 'saw POST /foo', cb) + .post('/foo') + .expect(200, 'saw POST /foo', cb) request(server) - .put('/foo') - .expect(200, 'saw PUT /foo', cb) + .put('/foo') + .expect(200, 'saw PUT /foo', cb) }) it('should accept multiple arguments', function (done) { @@ -151,10 +151,10 @@ describe('Router', function () { route.all(createHitHandle(1), createHitHandle(2), helloWorld) request(server) - .get('/foo') - .expect('x-fn-1', 'hit') - .expect('x-fn-2', 'hit') - .expect(200, 'hello, world', done) + .get('/foo') + .expect('x-fn-1', 'hit') + .expect('x-fn-2', 'hit') + .expect(200, 'hello, world', done) }) it('should accept single array of handlers', function (done) { @@ -165,10 +165,10 @@ describe('Router', function () { route.all([createHitHandle(1), createHitHandle(2), helloWorld]) request(server) - .get('/foo') - .expect('x-fn-1', 'hit') - .expect('x-fn-2', 'hit') - .expect(200, 'hello, world', done) + .get('/foo') + .expect('x-fn-1', 'hit') + .expect('x-fn-2', 'hit') + .expect(200, 'hello, world', done) }) it('should accept nested arrays of handlers', function (done) { @@ -179,11 +179,11 @@ describe('Router', function () { route.all([[createHitHandle(1), createHitHandle(2)], createHitHandle(3)], helloWorld) request(server) - .get('/foo') - .expect('x-fn-1', 'hit') - .expect('x-fn-2', 'hit') - .expect('x-fn-3', 'hit') - .expect(200, 'hello, world', done) + .get('/foo') + .expect('x-fn-1', 'hit') + .expect('x-fn-2', 'hit') + .expect('x-fn-3', 'hit') + .expect(200, 'hello, world', done) }) }) @@ -298,8 +298,8 @@ describe('Router', function () { }) request(server) - .get('/foo') - .expect(500, 'caught: boom!', done) + .get('/foo') + .expect(500, 'caught: boom!', done) }) it('should handle errors thrown', function (done) { @@ -319,8 +319,8 @@ describe('Router', function () { }) request(server) - .get('/foo') - .expect(500, 'caught: boom!', done) + .get('/foo') + .expect(500, 'caught: boom!', done) }) it('should handle errors thrown in error handlers', function (done) { @@ -342,8 +342,8 @@ describe('Router', function () { }) request(server) - .get('/foo') - .expect(500, 'caught: oh, no!', done) + .get('/foo') + .expect(500, 'caught: oh, no!', done) }) }) @@ -361,9 +361,9 @@ describe('Router', function () { router.use(saw) request(server) - .get('/foo') - .expect('x-next', 'route') - .expect(200, 'saw GET /foo', done) + .get('/foo') + .expect('x-next', 'route') + .expect(200, 'saw GET /foo', done) }) it('should invoke next route', function (done) { @@ -379,9 +379,9 @@ describe('Router', function () { router.route('/foo').all(saw) request(server) - .get('/foo') - .expect('x-next', 'route') - .expect(200, 'saw GET /foo', done) + .get('/foo') + .expect('x-next', 'route') + .expect(200, 'saw GET /foo', done) }) it('should skip next handlers in route', function (done) { @@ -399,11 +399,11 @@ describe('Router', function () { router.use(saw) request(server) - .get('/foo') - .expect(shouldHitHandle(1)) - .expect('x-next', 'route') - .expect(shouldNotHitHandle(2)) - .expect(200, 'saw GET /foo', done) + .get('/foo') + .expect(shouldHitHandle(1)) + .expect('x-next', 'route') + .expect(shouldNotHitHandle(2)) + .expect(200, 'saw GET /foo', done) }) it('should not invoke error handlers', function (done) { @@ -422,9 +422,9 @@ describe('Router', function () { }) request(server) - .get('/foo') - .expect('x-next', 'route') - .expect(404, done) + .get('/foo') + .expect('x-next', 'route') + .expect(404, done) }) }) @@ -444,10 +444,10 @@ describe('Router', function () { router.use(saw) request(server) - .get('/foo') - .expect('x-next', 'router') - .expect(shouldNotHitHandle(1)) - .expect(404, done) + .get('/foo') + .expect('x-next', 'router') + .expect(shouldNotHitHandle(1)) + .expect(404, done) }) it('should not invoke error handlers', function (done) { @@ -471,9 +471,9 @@ describe('Router', function () { }) request(server) - .get('/foo') - .expect('x-next', 'router') - .expect(404, done) + .get('/foo') + .expect('x-next', 'router') + .expect(404, done) }) }) @@ -487,8 +487,8 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/bar') - .expect(200, {'foo': 'bar'}, done) + .get('/bar') + .expect(200, {'foo': 'bar'}, done) }) it('should match single path segment', function (done) { @@ -499,8 +499,8 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/bar/bar') - .expect(404, done) + .get('/bar/bar') + .expect(404, done) }) it('should work multiple times', function (done) { @@ -511,8 +511,8 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/fizz/buzz') - .expect(200, {'foo': 'fizz', 'bar': 'buzz'}, done) + .get('/fizz/buzz') + .expect(200, {'foo': 'fizz', 'bar': 'buzz'}, done) }) it('should work following a partial capture group', function (done) { @@ -524,12 +524,12 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/user/tj/edit') - .expect(200, {'user': 'tj', 'op': 'edit'}, cb) + .get('/user/tj/edit') + .expect(200, {'user': 'tj', 'op': 'edit'}, cb) request(server) - .get('/users/tj/edit') - .expect(200, {'0': 's', 'user': 'tj', 'op': 'edit'}, cb) + .get('/users/tj/edit') + .expect(200, {'0': 's', 'user': 'tj', 'op': 'edit'}, cb) }) it('should work inside literal paranthesis', function (done) { @@ -540,8 +540,8 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/tj(edit)') - .expect(200, {'user': 'tj', 'op': 'edit'}, done) + .get('/tj(edit)') + .expect(200, {'user': 'tj', 'op': 'edit'}, done) }) it('should work within arrays', function (done) { @@ -553,12 +553,12 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/user/tj/poke') - .expect(200, {'user': 'tj'}, cb) + .get('/user/tj/poke') + .expect(200, {'user': 'tj'}, cb) request(server) - .get('/user/tj/pokes') - .expect(200, {'user': 'tj'}, cb) + .get('/user/tj/pokes') + .expect(200, {'user': 'tj'}, cb) }) }) @@ -571,8 +571,8 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/foo/bar/baz') - .expect(200, {'0': '/foo/bar/baz'}, done) + .get('/foo/bar/baz') + .expect(200, {'0': '/foo/bar/baz'}, done) }) it('should decode the capture', function (done) { @@ -583,8 +583,8 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/foo/%20/baz') - .expect(200, {'0': '/foo/ /baz'}, done) + .get('/foo/%20/baz') + .expect(200, {'0': '/foo/ /baz'}, done) }) it('should capture everything with pre- and post-fixes', function (done) { @@ -595,8 +595,8 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/foo/1/2/3/bar') - .expect(200, {'0': '1/2/3'}, done) + .get('/foo/1/2/3/bar') + .expect(200, {'0': '1/2/3'}, done) }) it('should capture greedly', function (done) { @@ -607,8 +607,8 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/foo/bar/bar/bar') - .expect(200, {'0': 'bar/bar'}, done) + .get('/foo/bar/bar/bar') + .expect(200, {'0': 'bar/bar'}, done) }) it('should be an optional capture', function (done) { @@ -619,8 +619,8 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/foo') - .expect(200, {'0': ''}, done) + .get('/foo') + .expect(200, {'0': ''}, done) }) it('should require preceeding /', function (done) { @@ -632,12 +632,12 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/foo') - .expect(404, cb) + .get('/foo') + .expect(404, cb) request(server) - .get('/foo/') - .expect(200, cb) + .get('/foo/') + .expect(200, cb) }) it('should work in a named parameter', function (done) { @@ -649,12 +649,12 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/bar') - .expect(200, {'0': 'bar', 'foo': 'bar'}, cb) + .get('/bar') + .expect(200, {'0': 'bar', 'foo': 'bar'}, cb) request(server) - .get('/fizz/buzz') - .expect(200, {'0': 'fizz/buzz', 'foo': 'fizz/buzz'}, cb) + .get('/fizz/buzz') + .expect(200, {'0': 'fizz/buzz', 'foo': 'fizz/buzz'}, cb) }) it('should work before a named parameter', function (done) { @@ -665,8 +665,8 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/poke/user/42') - .expect(200, {'0': 'poke', 'id': '42'}, done) + .get('/poke/user/42') + .expect(200, {'0': 'poke', 'id': '42'}, done) }) it('should work within arrays', function (done) { @@ -678,16 +678,16 @@ describe('Router', function () { route.all(sendParams) request(server) - .get('/user/42') - .expect(200, {'id': '42'}, cb) + .get('/user/42') + .expect(200, {'id': '42'}, cb) request(server) - .get('/foo/bar') - .expect(200, {'0': 'bar'}, cb) + .get('/foo/bar') + .expect(200, {'0': 'bar'}, cb) request(server) - .get('/poke') - .expect(200, {'action': 'poke'}, cb) + .get('/poke') + .expect(200, {'action': 'poke'}, cb) }) }) }) diff --git a/test/router.js b/test/router.js index 8b49dab..526e4e0 100644 --- a/test/router.js +++ b/test/router.js @@ -73,16 +73,16 @@ describe('Router', function () { router.all(['/foo', '/bar'], saw) request(server) - .get('/') - .expect(404, cb) + .get('/') + .expect(404, cb) request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) + .get('/foo') + .expect(200, 'saw GET /foo', cb) request(server) - .get('/bar') - .expect(200, 'saw GET /bar', cb) + .get('/bar') + .expect(200, 'saw GET /bar', cb) }) it('should support regexp path', function (done) { @@ -93,16 +93,16 @@ describe('Router', function () { router.all(/^\/[a-z]oo$/, saw) request(server) - .get('/') - .expect(404, cb) + .get('/') + .expect(404, cb) request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) + .get('/foo') + .expect(200, 'saw GET /foo', cb) request(server) - .get('/zoo') - .expect(200, 'saw GET /zoo', cb) + .get('/zoo') + .expect(200, 'saw GET /zoo', cb) }) it('should support parameterized path', function (done) { @@ -113,20 +113,20 @@ describe('Router', function () { router.all('/:thing', saw) request(server) - .get('/') - .expect(404, cb) + .get('/') + .expect(404, cb) request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) + .get('/foo') + .expect(200, 'saw GET /foo', cb) request(server) - .get('/bar') - .expect(200, 'saw GET /bar', cb) + .get('/bar') + .expect(200, 'saw GET /bar', cb) request(server) - .get('/foo/bar') - .expect(404, cb) + .get('/foo/bar') + .expect(404, cb) }) it('should not stack overflow with many registered routes', function (done) { @@ -142,8 +142,8 @@ describe('Router', function () { router.get('/', helloWorld) request(server) - .get('/') - .expect(200, 'hello, world', done) + .get('/') + .expect(200, 'hello, world', done) }) describe('with "caseSensitive" option', function () { @@ -155,16 +155,16 @@ describe('Router', function () { router.all('/foo/bar', saw) request(server) - .get('/foo/bar') - .expect(200, 'saw GET /foo/bar', cb) + .get('/foo/bar') + .expect(200, 'saw GET /foo/bar', cb) request(server) - .get('/FOO/bar') - .expect(200, 'saw GET /FOO/bar', cb) + .get('/FOO/bar') + .expect(200, 'saw GET /FOO/bar', cb) request(server) - .get('/FOO/BAR') - .expect(200, 'saw GET /FOO/BAR', cb) + .get('/FOO/BAR') + .expect(200, 'saw GET /FOO/BAR', cb) }) it('should not match paths case-sensitively when false', function (done) { @@ -175,16 +175,16 @@ describe('Router', function () { router.all('/foo/bar', saw) request(server) - .get('/foo/bar') - .expect(200, 'saw GET /foo/bar', cb) + .get('/foo/bar') + .expect(200, 'saw GET /foo/bar', cb) request(server) - .get('/FOO/bar') - .expect(200, 'saw GET /FOO/bar', cb) + .get('/FOO/bar') + .expect(200, 'saw GET /FOO/bar', cb) request(server) - .get('/FOO/BAR') - .expect(200, 'saw GET /FOO/BAR', cb) + .get('/FOO/BAR') + .expect(200, 'saw GET /FOO/BAR', cb) }) it('should match paths case-sensitively when true', function (done) { @@ -195,16 +195,16 @@ describe('Router', function () { router.all('/foo/bar', saw) request(server) - .get('/foo/bar') - .expect(200, 'saw GET /foo/bar', cb) + .get('/foo/bar') + .expect(200, 'saw GET /foo/bar', cb) request(server) - .get('/FOO/bar') - .expect(404, cb) + .get('/FOO/bar') + .expect(404, cb) request(server) - .get('/FOO/BAR') - .expect(404, cb) + .get('/FOO/BAR') + .expect(404, cb) }) }) @@ -217,12 +217,12 @@ describe('Router', function () { router.all('/foo', saw) request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) + .get('/foo') + .expect(200, 'saw GET /foo', cb) request(server) - .get('/foo/') - .expect(200, 'saw GET /foo/', cb) + .get('/foo/') + .expect(200, 'saw GET /foo/', cb) }) it('should accept optional trailing slashes when false', function (done) { @@ -233,12 +233,12 @@ describe('Router', function () { router.all('/foo', saw) request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) + .get('/foo') + .expect(200, 'saw GET /foo', cb) request(server) - .get('/foo/') - .expect(200, 'saw GET /foo/', cb) + .get('/foo/') + .expect(200, 'saw GET /foo/', cb) }) it('should not accept optional trailing slashes when true', function (done) { @@ -249,12 +249,12 @@ describe('Router', function () { router.all('/foo', saw) request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) + .get('/foo') + .expect(200, 'saw GET /foo', cb) request(server) - .get('/foo/') - .expect(404, cb) + .get('/foo/') + .expect(404, cb) }) }) }) @@ -409,9 +409,9 @@ describe('Router', function () { }) request(server) - [method]('/foo') - .expect('x-url-base', '""') - .expect(200, done) + [method]('/foo') + .expect('x-url-base', '""') + .expect(200, done) }) }) @@ -426,9 +426,9 @@ describe('Router', function () { }) request(server) - [method]('/foo') - .expect('x-is-route', 'true') - .expect(200, done) + [method]('/foo') + .expect('x-is-route', 'true') + .expect(200, done) }) it('should be the matched route', function (done) { @@ -441,9 +441,9 @@ describe('Router', function () { }) request(server) - [method]('/foo') - .expect('x-is-route', 'true') - .expect(200, done) + [method]('/foo') + .expect('x-is-route', 'true') + .expect(200, done) }) }) }) @@ -481,20 +481,20 @@ describe('Router', function () { router.use(saw) request(server) - .get('/') - .expect(200, 'saw GET /', cb) + .get('/') + .expect(200, 'saw GET /', cb) request(server) - .put('/') - .expect(200, 'saw PUT /', cb) + .put('/') + .expect(200, 'saw PUT /', cb) request(server) - .post('/foo') - .expect(200, 'saw POST /foo', cb) + .post('/foo') + .expect(200, 'saw POST /foo', cb) rawrequest(server) - .options('*') - .expect(200, 'saw OPTIONS *', cb) + .options('*') + .expect(200, 'saw OPTIONS *', cb) }) it('should not invoke for blank URLs', function (done) { @@ -507,8 +507,8 @@ describe('Router', function () { router.use(saw) request(server) - .get('/') - .expect(404, done) + .get('/') + .expect(404, done) }) it('should support another router', function (done) { @@ -520,8 +520,8 @@ describe('Router', function () { router.use(inner) request(server) - .get('/') - .expect(200, 'saw GET /', done) + .get('/') + .expect(200, 'saw GET /', done) }) it('should accept multiple arguments', function (done) { @@ -531,10 +531,10 @@ describe('Router', function () { router.use(createHitHandle(1), createHitHandle(2), helloWorld) request(server) - .get('/') - .expect(shouldHitHandle(1)) - .expect(shouldHitHandle(2)) - .expect(200, 'hello, world', done) + .get('/') + .expect(shouldHitHandle(1)) + .expect(shouldHitHandle(2)) + .expect(200, 'hello, world', done) }) it('should accept single array of middleware', function (done) { @@ -544,10 +544,10 @@ describe('Router', function () { router.use([createHitHandle(1), createHitHandle(2), helloWorld]) request(server) - .get('/') - .expect(shouldHitHandle(1)) - .expect(shouldHitHandle(2)) - .expect(200, 'hello, world', done) + .get('/') + .expect(shouldHitHandle(1)) + .expect(shouldHitHandle(2)) + .expect(200, 'hello, world', done) }) it('should accept nested arrays of middleware', function (done) { @@ -557,11 +557,11 @@ describe('Router', function () { router.use([[createHitHandle(1), createHitHandle(2)], createHitHandle(3)], helloWorld) request(server) - .get('/') - .expect(shouldHitHandle(1)) - .expect(shouldHitHandle(2)) - .expect(shouldHitHandle(3)) - .expect(200, 'hello, world', done) + .get('/') + .expect(shouldHitHandle(1)) + .expect(shouldHitHandle(2)) + .expect(shouldHitHandle(3)) + .expect(200, 'hello, world', done) }) it('should not invoke singular error function', function (done) { @@ -573,8 +573,8 @@ describe('Router', function () { }) request(server) - .get('/') - .expect(404, done) + .get('/') + .expect(404, done) }) describe('error handling', function () { @@ -589,8 +589,8 @@ describe('Router', function () { router.use(sawError) request(server) - .get('/') - .expect(200, 'saw Error: boom!', done) + .get('/') + .expect(200, 'saw Error: boom!', done) }) it('should invoke error function after throw err', function (done) { @@ -604,8 +604,8 @@ describe('Router', function () { router.use(sawError) request(server) - .get('/') - .expect(200, 'saw Error: boom!', done) + .get('/') + .expect(200, 'saw Error: boom!', done) }) it('should not invoke error functions above function', function (done) { @@ -619,8 +619,8 @@ describe('Router', function () { }) request(server) - .get('/') - .expect(500, done) + .get('/') + .expect(500, done) }) }) @@ -637,9 +637,9 @@ describe('Router', function () { router.use(saw) request(server) - .get('/') - .expect('x-next', 'route') - .expect(200, 'saw GET /', done) + .get('/') + .expect('x-next', 'route') + .expect(200, 'saw GET /', done) }) it('should invoke next function', function (done) { @@ -654,11 +654,11 @@ describe('Router', function () { router.use(createHitHandle(1), goNext, createHitHandle(2), saw) request(server) - .get('/') - .expect(shouldHitHandle(1)) - .expect('x-next', 'route') - .expect(shouldHitHandle(2)) - .expect(200, 'saw GET /', done) + .get('/') + .expect(shouldHitHandle(1)) + .expect('x-next', 'route') + .expect(shouldHitHandle(2)) + .expect(200, 'saw GET /', done) }) it('should not invoke error handlers', function (done) { @@ -673,9 +673,9 @@ describe('Router', function () { router.use(sawError) request(server) - .get('/') - .expect('x-next', 'route') - .expect(404, done) + .get('/') + .expect('x-next', 'route') + .expect(404, done) }) }) @@ -693,10 +693,10 @@ describe('Router', function () { router.use(saw) request(server) - .get('/') - .expect('x-next', 'router') - .expect(shouldNotHitHandle(1)) - .expect(404, done) + .get('/') + .expect('x-next', 'router') + .expect(shouldNotHitHandle(1)) + .expect(404, done) }) it('should not invoke error handlers', function (done) { @@ -711,9 +711,9 @@ describe('Router', function () { router.use(sawError) request(server) - .get('/') - .expect('x-next', 'router') - .expect(404, done) + .get('/') + .expect('x-next', 'router') + .expect(404, done) }) }) @@ -725,8 +725,8 @@ describe('Router', function () { router.use(sawBase) request(server) - .get('/foo/bar') - .expect(200, 'saw ', done) + .get('/foo/bar') + .expect(200, 'saw ', done) }) }) }) @@ -745,16 +745,16 @@ describe('Router', function () { router.use('/foo', saw) request(server) - .get('/') - .expect(404, cb) + .get('/') + .expect(404, cb) request(server) - .post('/foo') - .expect(200, 'saw POST /', cb) + .post('/foo') + .expect(200, 'saw POST /', cb) request(server) - .post('/foo/bar') - .expect(200, 'saw POST /bar', cb) + .post('/foo/bar') + .expect(200, 'saw POST /bar', cb) }) it('should match if path has trailing slash', function (done) { @@ -765,16 +765,16 @@ describe('Router', function () { router.use('/foo/', saw) request(server) - .get('/') - .expect(404, cb) + .get('/') + .expect(404, cb) request(server) - .post('/foo') - .expect(200, 'saw POST /', cb) + .post('/foo') + .expect(200, 'saw POST /', cb) request(server) - .post('/foo/bar') - .expect(200, 'saw POST /bar', cb) + .post('/foo/bar') + .expect(200, 'saw POST /bar', cb) }) it('should support array of paths', function (done) { @@ -785,16 +785,16 @@ describe('Router', function () { router.use(['/foo/', '/bar'], saw) request(server) - .get('/') - .expect(404, cb) + .get('/') + .expect(404, cb) request(server) - .get('/foo') - .expect(200, 'saw GET /', cb) + .get('/foo') + .expect(200, 'saw GET /', cb) request(server) - .get('/bar') - .expect(200, 'saw GET /', cb) + .get('/bar') + .expect(200, 'saw GET /', cb) }) it('should support regexp path', function (done) { @@ -805,24 +805,24 @@ describe('Router', function () { router.use(/^\/[a-z]oo/, saw) request(server) - .get('/') - .expect(404, cb) + .get('/') + .expect(404, cb) request(server) - .get('/foo') - .expect(200, 'saw GET /', cb) + .get('/foo') + .expect(200, 'saw GET /', cb) request(server) - .get('/fooo') - .expect(404, cb) + .get('/fooo') + .expect(404, cb) request(server) - .get('/zoo/bear') - .expect(200, 'saw GET /bear', cb) + .get('/zoo/bear') + .expect(200, 'saw GET /bear', cb) request(server) - .get('/get/zoo') - .expect(404, cb) + .get('/get/zoo') + .expect(404, cb) }) it('should support parameterized path', function (done) { @@ -833,20 +833,20 @@ describe('Router', function () { router.use('/:thing', saw) request(server) - .get('/') - .expect(404, cb) + .get('/') + .expect(404, cb) request(server) - .get('/foo') - .expect(200, 'saw GET /', cb) + .get('/foo') + .expect(200, 'saw GET /', cb) request(server) - .get('/bar') - .expect(200, 'saw GET /', cb) + .get('/bar') + .expect(200, 'saw GET /', cb) request(server) - .get('/foo/bar') - .expect(200, 'saw GET /bar', cb) + .get('/foo/bar') + .expect(200, 'saw GET /bar', cb) }) it('should accept multiple arguments', function (done) { @@ -856,10 +856,10 @@ describe('Router', function () { router.use('/foo', createHitHandle(1), createHitHandle(2), helloWorld) request(server) - .get('/foo') - .expect(shouldHitHandle(1)) - .expect(shouldHitHandle(2)) - .expect(200, 'hello, world', done) + .get('/foo') + .expect(shouldHitHandle(1)) + .expect(shouldHitHandle(2)) + .expect(200, 'hello, world', done) }) describe('with "caseSensitive" option', function () { @@ -871,16 +871,16 @@ describe('Router', function () { router.use('/foo', saw) request(server) - .get('/foo/bar') - .expect(200, 'saw GET /bar', cb) + .get('/foo/bar') + .expect(200, 'saw GET /bar', cb) request(server) - .get('/FOO/bar') - .expect(200, 'saw GET /bar', cb) + .get('/FOO/bar') + .expect(200, 'saw GET /bar', cb) request(server) - .get('/FOO/BAR') - .expect(200, 'saw GET /BAR', cb) + .get('/FOO/BAR') + .expect(200, 'saw GET /BAR', cb) }) it('should not match paths case-sensitively when false', function (done) { @@ -891,16 +891,16 @@ describe('Router', function () { router.use('/foo', saw) request(server) - .get('/foo/bar') - .expect(200, 'saw GET /bar', cb) + .get('/foo/bar') + .expect(200, 'saw GET /bar', cb) request(server) - .get('/FOO/bar') - .expect(200, 'saw GET /bar', cb) + .get('/FOO/bar') + .expect(200, 'saw GET /bar', cb) request(server) - .get('/FOO/BAR') - .expect(200, 'saw GET /BAR', cb) + .get('/FOO/BAR') + .expect(200, 'saw GET /BAR', cb) }) it('should match paths case-sensitively when true', function (done) { @@ -911,16 +911,16 @@ describe('Router', function () { router.use('/foo', saw) request(server) - .get('/foo/bar') - .expect(200, 'saw GET /bar', cb) + .get('/foo/bar') + .expect(200, 'saw GET /bar', cb) request(server) - .get('/FOO/bar') - .expect(404, cb) + .get('/FOO/bar') + .expect(404, cb) request(server) - .get('/FOO/BAR') - .expect(404, cb) + .get('/FOO/BAR') + .expect(404, cb) }) }) @@ -933,12 +933,12 @@ describe('Router', function () { router.use('/foo', saw) request(server) - .get('/foo') - .expect(200, 'saw GET /', cb) + .get('/foo') + .expect(200, 'saw GET /', cb) request(server) - .get('/foo/') - .expect(200, 'saw GET /', cb) + .get('/foo/') + .expect(200, 'saw GET /', cb) }) it('should accept optional trailing slashes when false', function (done) { @@ -949,12 +949,12 @@ describe('Router', function () { router.use('/foo', saw) request(server) - .get('/foo') - .expect(200, 'saw GET /', cb) + .get('/foo') + .expect(200, 'saw GET /', cb) request(server) - .get('/foo/') - .expect(200, 'saw GET /', cb) + .get('/foo/') + .expect(200, 'saw GET /', cb) }) it('should accept optional trailing slashes when true', function (done) { @@ -965,12 +965,12 @@ describe('Router', function () { router.use('/foo', saw) request(server) - .get('/foo') - .expect(200, 'saw GET /', cb) + .get('/foo') + .expect(200, 'saw GET /', cb) request(server) - .get('/foo/') - .expect(200, 'saw GET /', cb) + .get('/foo/') + .expect(200, 'saw GET /', cb) }) }) @@ -987,9 +987,9 @@ describe('Router', function () { router.use('/foo', saw) request(server) - .get('/foo') - .expect('x-next', 'route') - .expect(200, 'saw GET /', done) + .get('/foo') + .expect('x-next', 'route') + .expect(200, 'saw GET /', done) }) it('should invoke next function', function (done) { @@ -1004,11 +1004,11 @@ describe('Router', function () { router.use('/foo', createHitHandle(1), goNext, createHitHandle(2), saw) request(server) - .get('/foo') - .expect(shouldHitHandle(1)) - .expect('x-next', 'route') - .expect(shouldHitHandle(2)) - .expect(200, 'saw GET /', done) + .get('/foo') + .expect(shouldHitHandle(1)) + .expect('x-next', 'route') + .expect(shouldHitHandle(2)) + .expect(200, 'saw GET /', done) }) }) @@ -1020,8 +1020,8 @@ describe('Router', function () { router.use('/foo', sawBase) request(server) - .get('/foo/bar') - .expect(200, 'saw /foo', done) + .get('/foo/bar') + .expect(200, 'saw /foo', done) }) it('should contain the stripped path for multiple levels', function (done) { @@ -1033,8 +1033,8 @@ describe('Router', function () { router2.use('/bar', sawBase) request(server) - .get('/foo/bar/baz') - .expect(200, 'saw /foo/bar', done) + .get('/foo/bar/baz') + .expect(200, 'saw /foo/bar', done) }) it('should be altered correctly', function(done){ @@ -1059,13 +1059,13 @@ describe('Router', function () { router.use(helloWorld) request(server) - .get('/foo/bar/baz/zed') - .expect('x-saw-base-1', '/foo/bar/baz') - .expect('x-saw-base-2', '/foo') - .expect('x-saw-base-3', '/foo/bar') - .expect('x-saw-base-4', '') - .expect('x-saw-base-5', '') - .expect(200, done) + .get('/foo/bar/baz/zed') + .expect('x-saw-base-1', '/foo/bar/baz') + .expect('x-saw-base-2', '/foo') + .expect('x-saw-base-3', '/foo/bar') + .expect('x-saw-base-4', '') + .expect('x-saw-base-5', '') + .expect(200, done) }) }) @@ -1077,8 +1077,8 @@ describe('Router', function () { router.use('/foo', saw) request(server) - .get('/foo/bar') - .expect(200, 'saw GET /bar', done) + .get('/foo/bar') + .expect(200, 'saw GET /bar', done) }) it('should restore req.url after stripping', function (done) { @@ -1089,9 +1089,9 @@ describe('Router', function () { router.use(saw) request(server) - .get('/foo/bar') - .expect('x-saw-1', 'GET /bar') - .expect(200, 'saw GET /foo/bar', done) + .get('/foo/bar') + .expect('x-saw-1', 'GET /bar') + .expect(200, 'saw GET /foo/bar', done) }) it('should strip/restore with trailing stash', function (done) { @@ -1102,9 +1102,9 @@ describe('Router', function () { router.use(saw) request(server) - .get('/foo/') - .expect('x-saw-1', 'GET /') - .expect(200, 'saw GET /foo/', done) + .get('/foo/') + .expect('x-saw-1', 'GET /') + .expect(200, 'saw GET /foo/', done) }) }) }) @@ -1125,12 +1125,12 @@ describe('Router', function () { router.use(saw) request(server) - .post('/foo') - .expect(shouldNotHitHandle(1)) - .expect(shouldHitHandle(2)) - .expect(shouldNotHitHandle(3)) - .expect(shouldHitHandle(4)) - .expect(200, 'saw PUT /foo', done) + .post('/foo') + .expect(shouldNotHitHandle(1)) + .expect(shouldHitHandle(2)) + .expect(shouldNotHitHandle(3)) + .expect(shouldHitHandle(4)) + .expect(200, 'saw PUT /foo', done) }) it('should support altering req.url', function (done) { @@ -1148,12 +1148,12 @@ describe('Router', function () { router.use(saw) request(server) - .get('/foo') - .expect(shouldNotHitHandle(1)) - .expect(shouldHitHandle(2)) - .expect(shouldNotHitHandle(3)) - .expect(shouldHitHandle(4)) - .expect(200, 'saw GET /bar', done) + .get('/foo') + .expect(shouldNotHitHandle(1)) + .expect(shouldHitHandle(2)) + .expect(shouldNotHitHandle(3)) + .expect(shouldHitHandle(4)) + .expect(200, 'saw GET /bar', done) }) }) }) From d901dc27ea9c2e95e900875507c689fb4c8bb612 Mon Sep 17 00:00:00 2001 From: Gabe Gorelick Date: Fri, 3 Jan 2020 10:36:07 -0500 Subject: [PATCH 019/207] build: support Node.js 12.x --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index acf57a9..47cb3b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ node_js: - "9.11" - "10.18" - "11.15" + - "12.14" sudo: false cache: directories: From 89910d0da8d5ab692cfc349cec9bb329ce78adc6 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 24 Jan 2020 01:09:23 -0500 Subject: [PATCH 020/207] build: support Node.js 13.x --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 47cb3b4..2317c2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ node_js: - "10.18" - "11.15" - "12.14" + - "13.7" sudo: false cache: directories: From 69c9aaa3779dcd4543fc9e7b169221c9e13ea204 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sun, 5 Jan 2020 09:05:51 -0800 Subject: [PATCH 021/207] build: mocha@7.0.0 --- .travis.yml | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2317c2e..947c73a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -71,6 +71,7 @@ before_install: if node_version_lt '0.10'; then npm_use_module 'mocha' '2.5.3' elif node_version_lt '4.0' ; then npm_use_module 'mocha' '3.5.3' elif node_version_lt '6.0' ; then npm_use_module 'mocha' '5.2.0' + elif node_version_lt '8.0' ; then npm_use_module 'mocha' '6.2.2' fi - | # Configure supertest for http calls diff --git a/package.json b/package.json index eeb34d8..5d09d58 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.0-beta.6", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "6.1.4", + "mocha": "7.0.0", "safe-buffer": "5.2.0", "supertest": "3.4.2" }, From be7b094b517628bc9b1016ab89a93ab37e51de37 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sun, 5 Jan 2020 09:24:47 -0800 Subject: [PATCH 022/207] build: supertest@4.0.2 --- .travis.yml | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 947c73a..dad577f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -77,6 +77,7 @@ before_install: # Configure supertest for http calls if node_version_lt '0.10'; then npm_use_module 'supertest' '1.1.0' elif node_version_lt '4.0' ; then npm_use_module 'supertest' '2.0.0' + elif node_version_lt '6.0' ; then npm_use_module 'supertest' '3.4.2' fi # Update Node.js modules - | diff --git a/package.json b/package.json index 5d09d58..a53fb6c 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "istanbul": "0.4.5", "mocha": "7.0.0", "safe-buffer": "5.2.0", - "supertest": "3.4.2" + "supertest": "4.0.2" }, "files": [ "lib/", From 24cb4a801ee8e308629d72dca2de33ce2cad443b Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sun, 5 Jan 2020 10:02:27 -0800 Subject: [PATCH 023/207] build: eslint-plugin-markdown@1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a53fb6c..14aeb43 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "devDependencies": { "after": "0.8.2", "eslint": "6.8.0", - "eslint-plugin-markdown": "1.0.0-beta.6", + "eslint-plugin-markdown": "1.0.1", "finalhandler": "1.1.2", "istanbul": "0.4.5", "mocha": "7.0.0", From 9b17adfb143b268706ec659529b363e620600a1c Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 24 Jan 2020 01:30:28 -0500 Subject: [PATCH 024/207] deps: array-flatten@3.0.0 --- HISTORY.md | 2 +- index.js | 2 +- lib/route.js | 2 +- package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 55f4ce1..48f0b50 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,7 +1,7 @@ unreleased ========== - * deps: array-flatten@2.1.2 + * deps: array-flatten@3.0.0 * deps: parseurl@~1.3.3 * deps: setprototypeof@1.2.0 diff --git a/index.js b/index.js index a8927da..9131254 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ */ var debug = require('debug')('router') -var flatten = require('array-flatten') +var flatten = require('array-flatten').flatten var Layer = require('./lib/layer') var methods = require('methods') var mixin = require('utils-merge') diff --git a/lib/route.js b/lib/route.js index c501b08..065178e 100644 --- a/lib/route.js +++ b/lib/route.js @@ -13,7 +13,7 @@ */ var debug = require('debug')('router:route') -var flatten = require('array-flatten') +var flatten = require('array-flatten').flatten var Layer = require('./layer') var methods = require('methods') diff --git a/package.json b/package.json index 14aeb43..4a72d3d 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "license": "MIT", "repository": "pillarjs/router", "dependencies": { - "array-flatten": "2.1.2", + "array-flatten": "3.0.0", "debug": "2.6.9", "methods": "~1.1.2", "parseurl": "~1.3.3", From bb424954aaa103e05eb34ce213fd796ebb9521a9 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 24 Jan 2020 01:36:12 -0500 Subject: [PATCH 025/207] build: add version script for npm version releases --- package.json | 3 +- scripts/version-history.js | 63 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 scripts/version-history.js diff --git a/package.json b/package.json index 4a72d3d..10460ae 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "lint": "eslint --plugin markdown --ext js,md .", "test": "mocha --reporter spec --bail --check-leaks test/", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", - "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/" + "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/", + "version": "node scripts/version-history.js && git add HISTORY.md" } } diff --git a/scripts/version-history.js b/scripts/version-history.js new file mode 100644 index 0000000..c58268a --- /dev/null +++ b/scripts/version-history.js @@ -0,0 +1,63 @@ +'use strict' + +var fs = require('fs') +var path = require('path') + +var HISTORY_FILE_PATH = path.join(__dirname, '..', 'HISTORY.md') +var MD_HEADER_REGEXP = /^====*$/ +var VERSION = process.env.npm_package_version +var VERSION_PLACEHOLDER_REGEXP = /^(?:unreleased|(\d+\.)+x)$/ + +var historyFileLines = fs.readFileSync(HISTORY_FILE_PATH, 'utf-8').split('\n') + +if (!MD_HEADER_REGEXP.test(historyFileLines[1])) { + console.error('Missing header in HISTORY.md') + process.exit(1) +} + +if (!VERSION_PLACEHOLDER_REGEXP.test(historyFileLines[0])) { + console.error('Missing placeholder version in HISTORY.md') + process.exit(1) +} + +if (historyFileLines[0].indexOf('x') !== -1) { + var versionCheckRegExp = new RegExp('^' + historyFileLines[0].replace('x', '.+') + '$') + + if (!versionCheckRegExp.test(VERSION)) { + console.error('Version %s does not match placeholder %s', VERSION, historyFileLines[0]) + process.exit(1) + } +} + +historyFileLines[0] = VERSION + ' / ' + getLocaleDate() +historyFileLines[1] = repeat('=', historyFileLines[0].length) + +fs.writeFileSync(HISTORY_FILE_PATH, historyFileLines.join('\n')) + +function getLocaleDate () { + var now = new Date() + + return zeroPad(now.getFullYear(), 4) + '-' + + zeroPad(now.getMonth() + 1, 2) + '-' + + zeroPad(now.getDate(), 2) +} + +function repeat (str, length) { + var out = '' + + for (var i = 0; i < length; i++) { + out += str + } + + return out +} + +function zeroPad (number, length) { + var num = number.toString() + + while (num.length < length) { + num = '0' + num + } + + return num +} From 0bb4608c8a8cd9fb5a142e4fc86d45c3df97c5d5 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 24 Jan 2020 21:16:10 -0500 Subject: [PATCH 026/207] 1.3.4 --- HISTORY.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 48f0b50..37eb5a9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,5 @@ -unreleased -========== +1.3.4 / 2020-01-24 +================== * deps: array-flatten@3.0.0 * deps: parseurl@~1.3.3 diff --git a/package.json b/package.json index 10460ae..72fad1c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "router", "description": "Simple middleware-style router", - "version": "1.3.3", + "version": "1.3.4", "author": "Douglas Christopher Wilson ", "contributors": [ "Blake Embrey " From e0bbb532ea6bc602abe17a4165b8a2694a86f11a Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sun, 5 Jan 2020 09:28:10 -0800 Subject: [PATCH 027/207] build: nyc@15.0.0 --- .travis.yml | 12 ++++++++++-- package.json | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a64f43d..2ab4f3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -67,6 +67,12 @@ before_install: elif node_version_lt '6.0'; then npm_use_module 'mocha' '5.2.0' elif node_version_lt '8.0'; then npm_use_module 'mocha' '6.2.2' fi + - | + # Configure nyc for testing + if node_version_lt '4.0'; then npm_use_module 'nyc' '10.3.2' + elif node_version_lt '6.0'; then npm_use_module 'nyc' '11.9.0' + elif node_version_lt '8.0'; then npm_use_module 'nyc' '14.1.1' + fi - | # Configure supertest for http calls if node_version_lt '4.0'; then npm_use_module 'supertest' '2.0.0' @@ -80,9 +86,11 @@ before_install: npm rebuild fi script: - # Run test script + # Run test script, depending on nyc install - | - npm test + if npm_module_installed 'nyc'; then npm run-script test-travis + else npm test + fi # Run linting, depending on eslint install - | if npm_module_installed 'eslint'; then npm run-script lint diff --git a/package.json b/package.json index f4e866f..959eebb 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.1", "finalhandler": "1.1.2", "mocha": "7.0.0", - "nyc": "10.3.2", + "nyc": "15.0.0", "safe-buffer": "5.2.0", "supertest": "4.0.2" }, From 07892222afdc133ec10f279ea2b9e8aa927084c2 Mon Sep 17 00:00:00 2001 From: Harshitha K P Date: Thu, 30 Jan 2020 15:47:28 +0530 Subject: [PATCH 028/207] docs: fix typo closes #89 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d346090..6be6155 100644 --- a/README.md +++ b/README.md @@ -148,8 +148,8 @@ var api = router.route('/api/') ## Router.Route(path) -Represents a single route as an instance that can be used can be used to handle -http `methods` with it's own, optional middleware. +Represents a single route as an instance that can be used to handle http +`methods` with it's own, optional middleware. ### route\[method](handler) From 2103c4a7ed56751e2a38de85c007e37afec103a8 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 20 Feb 2020 23:09:07 -0500 Subject: [PATCH 029/207] build: Node.js@10.19 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dad577f..600210b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ node_js: - "7.10" - "8.17" - "9.11" - - "10.18" + - "10.19" - "11.15" - "12.14" - "13.7" From c88fe965ae54a7a19b5a657264830a97f124df5f Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 22 Feb 2020 20:40:05 -0500 Subject: [PATCH 030/207] build: Node.js@12.16 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 600210b..03b7418 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ node_js: - "9.11" - "10.19" - "11.15" - - "12.14" + - "12.16" - "13.7" sudo: false cache: From 125cd5a26ec74368de7cd309f9535391c9d2447e Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 22 Feb 2020 20:49:02 -0500 Subject: [PATCH 031/207] build: Node.js@13.9 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 03b7418..44c3122 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ node_js: - "10.19" - "11.15" - "12.16" - - "13.7" + - "13.9" sudo: false cache: directories: From 74e3e58d4a5197ebe7f69817ac8fa445cacfe394 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 24 Feb 2020 19:33:36 -0500 Subject: [PATCH 032/207] build: mocha@7.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 72fad1c..8ed33c0 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.1", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "7.0.0", + "mocha": "7.0.1", "safe-buffer": "5.2.0", "supertest": "4.0.2" }, From 519ea1e9800168ba0d223bd25513f15e40f74106 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 28 Feb 2020 23:40:21 -0500 Subject: [PATCH 033/207] build: eslint-plugin-markdown@1.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ed33c0..5abee24 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "devDependencies": { "after": "0.8.2", "eslint": "6.8.0", - "eslint-plugin-markdown": "1.0.1", + "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", "mocha": "7.0.1", From 4acf108bcd52c16e52ce31256e757580398265d9 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sun, 5 Jan 2020 09:49:46 -0800 Subject: [PATCH 034/207] deps: path-to-regexp@3.2.0 closes #42 --- HISTORY.md | 11 ++++ lib/layer.js | 25 +++++---- package.json | 2 +- test/req.params.js | 4 +- test/route.js | 129 ++++++++++++++++++++++----------------------- 5 files changed, 92 insertions(+), 79 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 18c03d8..85ae9c9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,17 @@ * deps: array-flatten@3.0.0 * deps: parseurl@~1.3.3 + * deps: path-to-regexp@3.2.0 + - Add new `?`, `*`, and `+` parameter modifiers + - Matching group expressions are only RegExp syntax. + `(*)` is no longer valid and must be written as `(.*)`, for example. + - Named matching groups no longer available by position in `req.params`. + `/:foo(.*)` only captures as `req.params.foo` and not available as + `req.parmas[0]`. + - Regular expressions can only be used in a matching group. + `/\\d+` is no longer valid and must be written as `/(\\d+)`. + - Special `*` path segment behavior removed. + `/foo/*/bar` will match a literal `*` as the middle segment. * deps: setprototypeof@1.2.0 2.0.0-alpha.1 / 2018-07-27 diff --git a/lib/layer.js b/lib/layer.js index c012165..8a8a99e 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -21,6 +21,7 @@ var debug = require('debug')('router:layer') */ var hasOwnProperty = Object.prototype.hasOwnProperty +var TRAILING_SLASH_REGEXP = /\/+$/ /** * Expose `Layer`. @@ -37,13 +38,13 @@ function Layer(path, options, fn) { var opts = options || {} this.handle = fn + this.keys = [] this.name = fn.name || '' this.params = undefined this.path = undefined - this.regexp = pathRegexp(path, this.keys = [], opts) + this.regexp = pathRegexp((opts.strict ? path : loosen(path)), this.keys, opts) // set fast path flags - this.regexp.fast_star = path === '*' this.regexp.fast_slash = path === '/' && opts.end === false } @@ -132,13 +133,6 @@ Layer.prototype.match = function match(path) { return true } - // fast path for * (everything matched in a param) - if (this.regexp.fast_star) { - this.params = {'0': decode_param(path)} - this.path = path - return true - } - // match the path match = this.regexp.exec(path) } @@ -208,3 +202,16 @@ function isPromise (val) { typeof val === 'object' && typeof val.then === 'function' } + +/** + * Loosens the given path for path-to-regexp matching. + */ +function loosen (path) { + if (path instanceof RegExp) { + return path + } + + return Array.isArray(path) + ? path.map(function (p) { return loosen(p) }) + : String(path).replace(TRAILING_SLASH_REGEXP, '') +} diff --git a/package.json b/package.json index 959eebb..b4ae56e 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "debug": "3.1.0", "methods": "~1.1.2", "parseurl": "~1.3.3", - "path-to-regexp": "0.1.7", + "path-to-regexp": "3.2.0", "setprototypeof": "1.2.0", "utils-merge": "1.0.1" }, diff --git a/test/req.params.js b/test/req.params.js index 46e5b19..9a8ade9 100644 --- a/test/req.params.js +++ b/test/req.params.js @@ -137,7 +137,7 @@ describe('req.params', function () { }) }) - router.get('/*', hitParams(1)) + router.get('/(.*)', hitParams(1)) request(server) .get('/buzz') @@ -156,7 +156,7 @@ describe('req.params', function () { }) }) - router.get('/*', hitParams(1)) + router.get('/(.*)', hitParams(1)) request(server) .get('/bar') diff --git a/test/route.js b/test/route.js index 8520e87..6aa96b2 100644 --- a/test/route.js +++ b/test/route.js @@ -655,18 +655,18 @@ describe('Router', function () { it('should work following a partial capture group', function (done) { var cb = after(2, done) var router = new Router() - var route = router.route('/user(s)?/:user/:op') + var route = router.route('/user(s?)/:user/:op') var server = createServer(router) route.all(sendParams) request(server) .get('/user/tj/edit') - .expect(200, {'user': 'tj', 'op': 'edit'}, cb) + .expect(200, { 0: '', user: 'tj', op: 'edit' }, cb) request(server) .get('/users/tj/edit') - .expect(200, {'0': 's', 'user': 'tj', 'op': 'edit'}, cb) + .expect(200, { 0: 's', user: 'tj', op: 'edit' }, cb) }) it('should work inside literal paranthesis', function (done) { @@ -699,132 +699,127 @@ describe('Router', function () { }) }) - describe('using "*"', function () { - it('should capture everything', function (done) { + describe('using ":name?"', function () { + it('should name an optional parameter', function (done) { + var cb = after(2, done) var router = new Router() - var route = router.route('*') + var route = router.route('/:foo?') var server = createServer(router) route.all(sendParams) request(server) - .get('/foo/bar/baz') - .expect(200, {'0': '/foo/bar/baz'}, done) - }) - - it('should decode the capture', function (done) { - var router = new Router() - var route = router.route('*') - var server = createServer(router) - - route.all(sendParams) + .get('/bar') + .expect(200, { foo: 'bar' }, cb) request(server) - .get('/foo/%20/baz') - .expect(200, {'0': '/foo/ /baz'}, done) + .get('/') + .expect(200, {}, cb) }) - it('should capture everything with pre- and post-fixes', function (done) { + it('should work in any segment', function (done) { + var cb = after(2, done) var router = new Router() - var route = router.route('/foo/*/bar') + var route = router.route('/user/:foo?/delete') var server = createServer(router) route.all(sendParams) request(server) - .get('/foo/1/2/3/bar') - .expect(200, {'0': '1/2/3'}, done) + .get('/user/bar/delete') + .expect(200, { foo: 'bar' }, cb) + + request(server) + .get('/user/delete') + .expect(200, {}, cb) }) + }) - it('should capture greedly', function (done) { + describe('using ":name*"', function () { + it('should name a zero-or-more repeated parameter', function (done) { + var cb = after(3, done) var router = new Router() - var route = router.route('/foo/*/bar') + var route = router.route('/:foo*') var server = createServer(router) route.all(sendParams) request(server) - .get('/foo/bar/bar/bar') - .expect(200, {'0': 'bar/bar'}, done) - }) - - it('should be an optional capture', function (done) { - var router = new Router() - var route = router.route('/foo*') - var server = createServer(router) + .get('/') + .expect(200, {}, cb) - route.all(sendParams) + request(server) + .get('/bar') + .expect(200, { foo: 'bar' }, cb) request(server) - .get('/foo') - .expect(200, {'0': ''}, done) + .get('/fizz/buzz') + .expect(200, { foo: 'fizz/buzz' }, cb) }) - it('should require preceeding /', function (done) { - var cb = after(2, done) + it('should work in any segment', function (done) { + var cb = after(3, done) var router = new Router() - var route = router.route('/foo/*') + var route = router.route('/user/:foo*/delete') var server = createServer(router) route.all(sendParams) request(server) - .get('/foo') - .expect(404, cb) + .get('/user/delete') + .expect(200, {}, cb) + + request(server) + .get('/user/bar/delete') + .expect(200, { foo: 'bar' }, cb) request(server) - .get('/foo/') - .expect(200, cb) + .get('/user/fizz/buzz/delete') + .expect(200, { foo: 'fizz/buzz' }, cb) }) + }) - it('should work in a named parameter', function (done) { - var cb = after(2, done) + describe('using ":name+"', function () { + it('should name a one-or-more repeated parameter', function (done) { + var cb = after(3, done) var router = new Router() - var route = router.route('/:foo(*)') + var route = router.route('/:foo+') var server = createServer(router) route.all(sendParams) request(server) - .get('/bar') - .expect(200, {'0': 'bar', 'foo': 'bar'}, cb) + .get('/') + .expect(404, cb) request(server) - .get('/fizz/buzz') - .expect(200, {'0': 'fizz/buzz', 'foo': 'fizz/buzz'}, cb) - }) - - it('should work before a named parameter', function (done) { - var router = new Router() - var route = router.route('/*/user/:id') - var server = createServer(router) - - route.all(sendParams) + .get('/bar') + .expect(200, { foo: 'bar' }, cb) request(server) - .get('/poke/user/42') - .expect(200, {'0': 'poke', 'id': '42'}, done) + .get('/fizz/buzz') + .expect(200, { foo: 'fizz/buzz' }, cb) }) - it('should work within arrays', function (done) { + it('should work in any segment', function (done) { var cb = after(3, done) var router = new Router() - var route = router.route(['/user/:id', '/foo/*', '/:action']) + var route = router.route('/user/:foo+/delete') var server = createServer(router) route.all(sendParams) request(server) - .get('/user/42') - .expect(200, {'id': '42'}, cb) + .get('/user/delete') + .expect(404, cb) request(server) - .get('/foo/bar') - .expect(200, {'0': 'bar'}, cb) + .get('/user/bar/delete') + .expect(200, { foo: 'bar' }, cb) request(server) - .get('/poke') - .expect(200, {'action': 'poke'}, cb) + .get('/user/fizz/buzz/delete') + .expect(200, { foo: 'fizz/buzz' }, cb) }) }) }) From e1733bd7502fe1ce7e3f1dbe23b3f535ad1be351 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 13 Mar 2020 00:56:21 -0400 Subject: [PATCH 035/207] Internalize private router.process_params method --- HISTORY.md | 1 + index.js | 184 ++++++++++++++++++++++++++--------------------------- 2 files changed, 92 insertions(+), 93 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 85ae9c9..29bcde3 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,7 @@ 2.x === + * Internalize private `router.process_params` method * deps: array-flatten@3.0.0 * deps: parseurl@~1.3.3 * deps: path-to-regexp@3.2.0 diff --git a/index.js b/index.js index 88c1c03..12b2e74 100644 --- a/index.js +++ b/index.js @@ -282,7 +282,7 @@ Router.prototype.handle = function handle(req, res, callback) { var layerPath = layer.path // this should be done for the layer - self.process_params(layer, paramcalled, req, res, function (err) { + processParams(self.params, layer, paramcalled, req, res, function (err) { if (err) { return next(layerError || err) } @@ -332,98 +332,6 @@ Router.prototype.handle = function handle(req, res, callback) { } } -/** - * Process any parameters for the layer. - * - * @private - */ - -Router.prototype.process_params = function process_params(layer, called, req, res, done) { - var params = this.params - - // captured parameters from the layer, keys and values - var keys = layer.keys - - // fast track - if (!keys || keys.length === 0) { - return done() - } - - var i = 0 - var name - var paramIndex = 0 - var key - var paramVal - var paramCallbacks - var paramCalled - - // process params in order - // param callbacks can be async - function param(err) { - if (err) { - return done(err) - } - - if (i >= keys.length ) { - return done() - } - - paramIndex = 0 - key = keys[i++] - name = key.name - paramVal = req.params[name] - paramCallbacks = params[name] - paramCalled = called[name] - - if (paramVal === undefined || !paramCallbacks) { - return param() - } - - // param previously called with same value or error occurred - if (paramCalled && (paramCalled.match === paramVal - || (paramCalled.error && paramCalled.error !== 'route'))) { - // restore value - req.params[name] = paramCalled.value - - // next param - return param(paramCalled.error) - } - - called[name] = paramCalled = { - error: null, - match: paramVal, - value: paramVal - } - - paramCallback() - } - - // single param callbacks - function paramCallback(err) { - var fn = paramCallbacks[paramIndex++] - - // store updated value - paramCalled.value = req.params[key.name] - - if (err) { - // store error - paramCalled.error = err - param(err) - return - } - - if (!fn) return param() - - try { - fn(req, res, paramCallback, paramVal, key.name) - } catch (e) { - paramCallback(e) - } - } - - param() -} - /** * Use the given middleware function, with optional path, defaulting to "/". * @@ -647,6 +555,96 @@ function mergeParams(params, parent) { return mixin(obj, params) } +/** + * Process any parameters for the layer. + * + * @private + */ + +function processParams (params, layer, called, req, res, done) { + // captured parameters from the layer, keys and values + var keys = layer.keys + + // fast track + if (!keys || keys.length === 0) { + return done() + } + + var i = 0 + var name + var paramIndex = 0 + var key + var paramVal + var paramCallbacks + var paramCalled + + // process params in order + // param callbacks can be async + function param (err) { + if (err) { + return done(err) + } + + if (i >= keys.length) { + return done() + } + + paramIndex = 0 + key = keys[i++] + name = key.name + paramVal = req.params[name] + paramCallbacks = params[name] + paramCalled = called[name] + + if (paramVal === undefined || !paramCallbacks) { + return param() + } + + // param previously called with same value or error occurred + if (paramCalled && (paramCalled.match === paramVal || + (paramCalled.error && paramCalled.error !== 'route'))) { + // restore value + req.params[name] = paramCalled.value + + // next param + return param(paramCalled.error) + } + + called[name] = paramCalled = { + error: null, + match: paramVal, + value: paramVal + } + + paramCallback() + } + + // single param callbacks + function paramCallback (err) { + var fn = paramCallbacks[paramIndex++] + + // store updated value + paramCalled.value = req.params[key.name] + + if (err) { + // store error + paramCalled.error = err + param(err) + return + } + + if (!fn) return param() + + try { + fn(req, res, paramCallback, paramVal, key.name) + } catch (e) { + paramCallback(e) + } + } + + param() +} + /** * Restore obj props after function * From 1adcf8557213c50214a5ad945f06a625d7827a0a Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 19 Mar 2020 22:54:53 -0400 Subject: [PATCH 036/207] build: Node.js@13.11 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 44c3122..4185521 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ node_js: - "10.19" - "11.15" - "12.16" - - "13.9" + - "13.11" sudo: false cache: directories: From a5fdae3b43181239e5e173c4efb50ccc47cc7237 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 21 Mar 2020 17:19:29 -0400 Subject: [PATCH 037/207] build: remove deprecated Travis CI directive --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4185521..a5dfafe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,6 @@ node_js: - "11.15" - "12.16" - "13.11" -sudo: false cache: directories: - node_modules From 93ab33ab9fa07b02c5055594b27d9f660daa0cba Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 21 Mar 2020 17:37:32 -0400 Subject: [PATCH 038/207] build: mocha@7.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5abee24..70f58c0 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "7.0.1", + "mocha": "7.1.1", "safe-buffer": "5.2.0", "supertest": "4.0.2" }, From 16ff25e050243477b44c0e54d01f839d6d018064 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 24 Mar 2020 02:00:34 -0400 Subject: [PATCH 039/207] Fix incorrect middleware execution with unanchored RegExps --- HISTORY.md | 5 +++++ index.js | 6 ++++++ test/router.js | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 37eb5a9..65bddaa 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * Fix incorrect middleware execution with unanchored `RegExp`s + 1.3.4 / 2020-01-24 ================== diff --git a/index.js b/index.js index 9131254..3608f26 100644 --- a/index.js +++ b/index.js @@ -302,6 +302,12 @@ Router.prototype.handle = function handle(req, res, callback) { function trim_prefix(layer, layerError, layerPath, path) { if (layerPath.length !== 0) { + // Validate path is a prefix match + if (layerPath !== path.substr(0, layerPath.length)) { + next(layerError) + return + } + // Validate path breaks on a path separator var c = path[layerPath.length] if (c && c !== '/') { diff --git a/test/router.js b/test/router.js index 526e4e0..138f221 100644 --- a/test/router.js +++ b/test/router.js @@ -825,6 +825,23 @@ describe('Router', function () { .expect(404, cb) }) + it('should ensure regexp matches path prefix', function (done) { + var router = new Router() + var server = createServer(router) + + router.use(/\/api.*/, createHitHandle(1)) + router.use(/api/, createHitHandle(2)) + router.use(/\/test/, createHitHandle(3)) + router.use(helloWorld) + + request(server) + .get('/test/api/1234') + .expect(shouldNotHitHandle(1)) + .expect(shouldNotHitHandle(2)) + .expect(shouldHitHandle(3)) + .expect(200, done) + }) + it('should support parameterized path', function (done) { var cb = after(4, done) var router = new Router() From 66cbc45897af0708ae78888f8afd35374f5ad7e6 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 24 Mar 2020 18:39:51 -0400 Subject: [PATCH 040/207] perf: use plain object for internal method map --- HISTORY.md | 1 + lib/route.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 65bddaa..7d6d223 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,7 @@ unreleased ========== * Fix incorrect middleware execution with unanchored `RegExp`s + * perf: use plain object for internal method map 1.3.4 / 2020-01-24 ================== diff --git a/lib/route.js b/lib/route.js index 065178e..98363fe 100644 --- a/lib/route.js +++ b/lib/route.js @@ -43,7 +43,7 @@ function Route(path) { this.stack = [] // route handlers for various http methods - this.methods = {} + this.methods = Object.create(null) } /** From fb3c003951191ced20bc88c2e3bbc5082daed2fd Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 24 Mar 2020 23:10:40 -0400 Subject: [PATCH 041/207] 1.3.5 --- HISTORY.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 7d6d223..1000457 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,5 @@ -unreleased -========== +1.3.5 / 2020-03-24 +================== * Fix incorrect middleware execution with unanchored `RegExp`s * perf: use plain object for internal method map diff --git a/package.json b/package.json index 70f58c0..0f2bd98 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "router", "description": "Simple middleware-style router", - "version": "1.3.4", + "version": "1.3.5", "author": "Douglas Christopher Wilson ", "contributors": [ "Blake Embrey " From f35898309078c9fec7864d8aa7da67911ef29d97 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 25 Mar 2020 00:44:04 -0400 Subject: [PATCH 042/207] lint: use camel case for identifiers --- .eslintrc | 1 + index.js | 16 ++++++++-------- lib/layer.js | 12 ++++++------ lib/route.js | 6 +++--- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.eslintrc b/.eslintrc index 07eb965..4bb6cb6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,6 @@ { "rules": { + "camelcase": "error", "eol-last": "error", "indent": ["error", 2, { "SwitchCase": 1 }], "no-trailing-spaces": "error", diff --git a/index.js b/index.js index 88fe7ee..9b9e72c 100644 --- a/index.js +++ b/index.js @@ -251,15 +251,15 @@ Router.prototype.handle = function handle(req, res, callback) { } var method = req.method - var has_method = route._handles_method(method) + var hasMethod = route._handlesMethod(method) // build up automatic options response - if (!has_method && method === 'OPTIONS' && methods) { + if (!hasMethod && method === 'OPTIONS' && methods) { methods.push.apply(methods, route._methods()) } // don't even bother matching route - if (!has_method && method !== 'HEAD') { + if (!hasMethod && method !== 'HEAD') { match = false continue } @@ -288,14 +288,14 @@ Router.prototype.handle = function handle(req, res, callback) { } if (route) { - return layer.handle_request(req, res, next) + return layer.handleRequest(req, res, next) } - trim_prefix(layer, layerError, layerPath, path) + trimPrefix(layer, layerError, layerPath, path) }) } - function trim_prefix(layer, layerError, layerPath, path) { + function trimPrefix (layer, layerError, layerPath, path) { if (layerPath.length !== 0) { // Validate path is a prefix match if (layerPath !== path.substr(0, layerPath.length)) { @@ -331,9 +331,9 @@ Router.prototype.handle = function handle(req, res, callback) { debug('%s %s : %s', layer.name, layerPath, req.originalUrl) if (layerError) { - layer.handle_error(layerError, req, res, next) + layer.handleError(layerError, req, res, next) } else { - layer.handle_request(req, res, next) + layer.handleRequest(req, res, next) } } } diff --git a/lib/layer.js b/lib/layer.js index 8a8a99e..46cbfea 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -45,7 +45,7 @@ function Layer(path, options, fn) { this.regexp = pathRegexp((opts.strict ? path : loosen(path)), this.keys, opts) // set fast path flags - this.regexp.fast_slash = path === '/' && opts.end === false + this.regexp._slash = path === '/' && opts.end === false } /** @@ -58,7 +58,7 @@ function Layer(path, options, fn) { * @api private */ -Layer.prototype.handle_error = function handle_error(error, req, res, next) { +Layer.prototype.handleError = function handleError (error, req, res, next) { var fn = this.handle if (fn.length !== 4) { @@ -90,7 +90,7 @@ Layer.prototype.handle_error = function handle_error(error, req, res, next) { * @api private */ -Layer.prototype.handle_request = function handle(req, res, next) { +Layer.prototype.handleRequest = function handleRequest (req, res, next) { var fn = this.handle if (fn.length > 3) { @@ -127,7 +127,7 @@ Layer.prototype.match = function match(path) { if (path != null) { // fast path non-ending match for / (any path matches) - if (this.regexp.fast_slash) { + if (this.regexp._slash) { this.params = {} this.path = '' return true @@ -154,7 +154,7 @@ Layer.prototype.match = function match(path) { for (var i = 1; i < match.length; i++) { var key = keys[i - 1] var prop = key.name - var val = decode_param(match[i]) + var val = decodeParam(match[i]) if (val !== undefined || !(hasOwnProperty.call(params, prop))) { params[prop] = val @@ -172,7 +172,7 @@ Layer.prototype.match = function match(path) { * @private */ -function decode_param(val){ +function decodeParam (val) { if (typeof val !== 'string' || val.length === 0) { return val } diff --git a/lib/route.js b/lib/route.js index 98363fe..53d0c63 100644 --- a/lib/route.js +++ b/lib/route.js @@ -50,7 +50,7 @@ function Route(path) { * @private */ -Route.prototype._handles_method = function _handles_method(method) { +Route.prototype._handlesMethod = function _handlesMethod (method) { if (this.methods._all) { return true } @@ -139,9 +139,9 @@ Route.prototype.dispatch = function dispatch(req, res, done) { } if (err) { - layer.handle_error(err, req, res, next) + layer.handleError(err, req, res, next) } else { - layer.handle_request(req, res, next) + layer.handleRequest(req, res, next) } } } From 5a4347151dc4bb2dc30d15f6101c98a1f2d427d5 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 26 Mar 2020 13:11:31 -0400 Subject: [PATCH 043/207] lint: apply standard 14 style --- .eslintrc | 9 ----- .eslintrc.yml | 2 + README.md | 47 ++++++++++++++--------- index.js | 42 ++++++++++----------- lib/layer.js | 4 +- lib/route.js | 14 +++---- package.json | 5 +++ test/.eslintrc.yml | 2 + test/auto-head.js | 6 +-- test/auto-options.js | 8 ++-- test/fqdn-url.js | 6 +-- test/param.js | 36 +++++++++--------- test/req.params.js | 18 ++++----- test/route.js | 64 ++++++++++++++----------------- test/router.js | 88 ++++++++++++++++++------------------------- test/support/utils.js | 24 ++++++------ 16 files changed, 182 insertions(+), 193 deletions(-) delete mode 100644 .eslintrc create mode 100644 .eslintrc.yml create mode 100644 test/.eslintrc.yml diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 4bb6cb6..0000000 --- a/.eslintrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "rules": { - "camelcase": "error", - "eol-last": "error", - "indent": ["error", 2, { "SwitchCase": 1 }], - "no-trailing-spaces": "error", - "semi": ["error", "never"] - } -} diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..1eece14 --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,2 @@ +root: true +extends: standard diff --git a/README.md b/README.md index ee43b4c..a498379 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,8 @@ $ npm install router ```js var finalhandler = require('finalhandler') -var http = require('http') -var Router = require('router') +var http = require('http') +var Router = require('router') var router = Router() router.get('/', function (req, res) { @@ -31,7 +31,7 @@ router.get('/', function (req, res) { res.end('Hello World!') }) -var server = http.createServer(function(req, res) { +var server = http.createServer(function (req, res) { router(req, res, finalhandler(req, res)) }) @@ -66,6 +66,8 @@ consider it one for handling `OPTIONS` requests. * Note: If a `path` is specified, that `path` is stripped from the start of `req.url`. + + ```js router.use(function (req, res, next) { // do your things @@ -89,6 +91,8 @@ the routing functionality in `router`. Method middleware and handlers follow usual [middleware](#middleware) behavior, except they will only be called when the method and path match the request. + + ```js // handle a `GET` request router.get('/', function (req, res) { @@ -116,6 +120,8 @@ which use normalized placeholders. For example a _:user_id_ parameter could automatically load a user's information from the database without any additional code: + + ```js router.param('user_id', function (req, res, next, id) { User.find(id, function (err, user) { @@ -142,6 +148,8 @@ Routes can be used to handle http `methods` with their own, optional middleware. Using `router.route(path)` is a recommended approach to avoiding duplicate route naming and thus typo errors. + + ```js var api = router.route('/api/') ``` @@ -156,6 +164,8 @@ Represents a single route as an instance that can be used to handle http These are functions which you can directly call on a route to register a new `handler` for the `method` on the route. + + ```js // handle a `GET` request var status = router.route('/status') @@ -173,12 +183,14 @@ Adds a handler for all HTTP methods to this route. The handler can behave like middleware and call `next` to continue processing rather than responding. + + ```js router.route('/') .all(function (req, res, next) { next() }) - .all(check_something) + .all(checkSomething) .get(function (req, res) { res.setHeader('Content-Type', 'text/plain; charset=utf-8') res.end('Hello World!') @@ -207,13 +219,15 @@ functions are "error handling middleware", and can be used for handling errors that occurred in previous handlers (E.g. from calling `next(err)`). This is most used when you want to define arbitrary rendering of errors. + + ```js router.get('/error_route', function (req, res, next) { return next(new Error('Bad Request')) }) router.use(function (err, req, res, next) { - res.end(err.message) //=> "Bad Request" + res.end(err.message) //= > "Bad Request" }) ``` @@ -225,18 +239,18 @@ bypassed - only error handling middleware will be invoked with an error. ```js // import our modules -var http = require('http') -var Router = require('router') +var http = require('http') +var Router = require('router') var finalhandler = require('finalhandler') -var compression = require('compression') -var bodyParser = require('body-parser') +var compression = require('compression') +var bodyParser = require('body-parser') // store our message to display -var message = "Hello World!" +var message = 'Hello World!' // initialize the router & server and add a final callback. var router = Router() -var server = http.createServer(function onRequest(req, res) { +var server = http.createServer(function onRequest (req, res) { router(req, res, finalhandler(req, res)) }) @@ -290,8 +304,8 @@ curl http://127.0.0.1:8080/api/set-message -X PATCH -H "Content-Type: applicatio ### Example using mergeParams ```js -var http = require('http') -var Router = require('router') +var http = require('http') +var Router = require('router') var finalhandler = require('finalhandler') // this example is about the mergeParams option @@ -299,8 +313,7 @@ var opts = { mergeParams: true } // make a router with out special options var router = Router(opts) -var server = http.createServer(function onRequest(req, res) { - +var server = http.createServer(function onRequest (req, res) { // set something to be passed into the router req.params = { type: 'kitten' } @@ -326,7 +339,7 @@ handler.get('/', function (req, res) { res.setHeader('Content-Type', 'text/plain; charset=utf-8') // will respond with the param of the router's parent route - res.end(path + '\n') + res.end(req.params.path + '\n') }) // make our http server listen to connections @@ -356,7 +369,7 @@ var Router = require('router') // create the router and server var router = new Router() -var server = http.createServer(function onRequest(req, res) { +var server = http.createServer(function onRequest (req, res) { router(req, res, finalhandler(req, res)) }) diff --git a/index.js b/index.js index 9b9e72c..dc71423 100644 --- a/index.js +++ b/index.js @@ -48,14 +48,14 @@ module.exports.Route = Route * @public */ -function Router(options) { +function Router (options) { if (!(this instanceof Router)) { return new Router(options) } var opts = options || {} - function router(req, res, next) { + function router (req, res, next) { router.handle(req, res, next) } @@ -111,7 +111,7 @@ Router.prototype = function () {} * @public */ -Router.prototype.param = function param(name, fn) { +Router.prototype.param = function param (name, fn) { if (!name) { throw new TypeError('argument name is required') } @@ -145,7 +145,7 @@ Router.prototype.param = function param(name, fn) { * @private */ -Router.prototype.handle = function handle(req, res, callback) { +Router.prototype.handle = function handle (req, res, callback) { if (!callback) { throw new TypeError('argument callback is required') } @@ -183,7 +183,7 @@ Router.prototype.handle = function handle(req, res, callback) { next() - function next(err) { + function next (err) { var layerError = err === 'route' ? null : err @@ -353,7 +353,7 @@ Router.prototype.handle = function handle(req, res, callback) { * @public */ -Router.prototype.use = function use(handler) { +Router.prototype.use = function use (handler) { var offset = 0 var path = '/' @@ -416,7 +416,7 @@ Router.prototype.use = function use(handler) { * @public */ -Router.prototype.route = function route(path) { +Router.prototype.route = function route (path) { var route = new Route(path) var layer = new Layer(path, { @@ -425,7 +425,7 @@ Router.prototype.route = function route(path) { end: true }, handle) - function handle(req, res, next) { + function handle (req, res, next) { route.dispatch(req, res, next) } @@ -436,7 +436,7 @@ Router.prototype.route = function route(path) { } // create Router#VERB functions -methods.concat('all').forEach(function(method){ +methods.concat('all').forEach(function (method) { Router.prototype[method] = function (path) { var route = this.route(path) route[method].apply(route, slice.call(arguments, 1)) @@ -452,8 +452,8 @@ methods.concat('all').forEach(function(method){ * @private */ -function generateOptionsResponder(res, methods) { - return function onDone(fn, err) { +function generateOptionsResponder (res, methods) { + return function onDone (fn, err) { if (err || methods.length === 0) { return fn(err) } @@ -469,7 +469,7 @@ function generateOptionsResponder(res, methods) { * @private */ -function getPathname(req) { +function getPathname (req) { try { return parseUrl(req).pathname } catch (err) { @@ -484,7 +484,7 @@ function getPathname(req) { * @private */ -function getProtohost(url) { +function getProtohost (url) { if (typeof url !== 'string' || url.length === 0 || url[0] === '/') { return undefined } @@ -508,7 +508,7 @@ function getProtohost(url) { * @private */ -function matchLayer(layer, path) { +function matchLayer (layer, path) { try { return layer.match(path) } catch (err) { @@ -522,7 +522,7 @@ function matchLayer(layer, path) { * @private */ -function mergeParams(params, parent) { +function mergeParams (params, parent) { if (typeof parent !== 'object' || !parent) { return params } @@ -657,7 +657,7 @@ function processParams (params, layer, called, req, res, done) { * @private */ -function restore(fn, obj) { +function restore (fn, obj) { var props = new Array(arguments.length - 2) var vals = new Array(arguments.length - 2) @@ -666,7 +666,7 @@ function restore(fn, obj) { vals[i] = obj[props[i]] } - return function(){ + return function () { // restore vals for (var i = 0; i < props.length; i++) { obj[props[i]] = vals[i] @@ -682,7 +682,7 @@ function restore(fn, obj) { * @private */ -function sendOptionsResponse(res, methods) { +function sendOptionsResponse (res, methods) { var options = Object.create(null) // build unique method map @@ -707,7 +707,7 @@ function sendOptionsResponse(res, methods) { * @private */ -function trySendOptionsResponse(res, methods, next) { +function trySendOptionsResponse (res, methods, next) { try { sendOptionsResponse(res, methods) } catch (err) { @@ -721,8 +721,8 @@ function trySendOptionsResponse(res, methods, next) { * @private */ -function wrap(old, fn) { - return function proxy() { +function wrap (old, fn) { + return function proxy () { var args = new Array(arguments.length + 1) args[0] = old diff --git a/lib/layer.js b/lib/layer.js index 46cbfea..f6365f9 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -29,7 +29,7 @@ var TRAILING_SLASH_REGEXP = /\/+$/ module.exports = Layer -function Layer(path, options, fn) { +function Layer (path, options, fn) { if (!(this instanceof Layer)) { return new Layer(path, options, fn) } @@ -122,7 +122,7 @@ Layer.prototype.handleRequest = function handleRequest (req, res, next) { * @api private */ -Layer.prototype.match = function match(path) { +Layer.prototype.match = function match (path) { var match if (path != null) { diff --git a/lib/route.js b/lib/route.js index 53d0c63..28a2266 100644 --- a/lib/route.js +++ b/lib/route.js @@ -37,7 +37,7 @@ module.exports = Route * @api private */ -function Route(path) { +function Route (path) { debug('new %o', path) this.path = path this.stack = [] @@ -58,7 +58,7 @@ Route.prototype._handlesMethod = function _handlesMethod (method) { // normalize name var name = method.toLowerCase() - if (name === 'head' && !this.methods['head']) { + if (name === 'head' && !this.methods.head) { name = 'get' } @@ -70,7 +70,7 @@ Route.prototype._handlesMethod = function _handlesMethod (method) { * @private */ -Route.prototype._methods = function _methods() { +Route.prototype._methods = function _methods () { var methods = Object.keys(this.methods) // append automatic head @@ -92,7 +92,7 @@ Route.prototype._methods = function _methods() { * @private */ -Route.prototype.dispatch = function dispatch(req, res, done) { +Route.prototype.dispatch = function dispatch (req, res, done) { var idx = 0 var stack = this.stack if (stack.length === 0) { @@ -100,7 +100,7 @@ Route.prototype.dispatch = function dispatch(req, res, done) { } var method = req.method.toLowerCase() - if (method === 'head' && !this.methods['head']) { + if (method === 'head' && !this.methods.head) { method = 'get' } @@ -108,7 +108,7 @@ Route.prototype.dispatch = function dispatch(req, res, done) { next() - function next(err) { + function next (err) { // signal to exit route if (err && err === 'route') { return done() @@ -174,7 +174,7 @@ Route.prototype.dispatch = function dispatch(req, res, done) { * @api public */ -Route.prototype.all = function all(handler) { +Route.prototype.all = function all (handler) { var callbacks = flatten(slice.call(arguments)) if (callbacks.length === 0) { diff --git a/package.json b/package.json index e8b5926..2ce21d2 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,12 @@ "devDependencies": { "after": "0.8.2", "eslint": "6.8.0", + "eslint-config-standard": "14.1.1", + "eslint-plugin-import": "2.20.1", "eslint-plugin-markdown": "1.0.2", + "eslint-plugin-node": "11.0.0", + "eslint-plugin-promise": "4.2.1", + "eslint-plugin-standard": "4.0.1", "finalhandler": "1.1.2", "mocha": "7.1.1", "nyc": "15.0.0", diff --git a/test/.eslintrc.yml b/test/.eslintrc.yml new file mode 100644 index 0000000..9808c3b --- /dev/null +++ b/test/.eslintrc.yml @@ -0,0 +1,2 @@ +env: + mocha: true diff --git a/test/auto-head.js b/test/auto-head.js index bb63145..2fd8580 100644 --- a/test/auto-head.js +++ b/test/auto-head.js @@ -34,16 +34,16 @@ describe('HEAD', function () { }) }) -function saw(req, res) { +function saw (req, res) { var msg = 'saw ' + req.method + ' ' + req.url res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) } -function sethit(num) { +function sethit (num) { var name = 'x-fn-' + String(num) - return function hit(req, res, next) { + return function hit (req, res, next) { res.setHeader(name, 'hit') next() } diff --git a/test/auto-options.js b/test/auto-options.js index ac90959..9cfd429 100644 --- a/test/auto-options.js +++ b/test/auto-options.js @@ -78,7 +78,7 @@ describe('OPTIONS', function () { describe('when error occurs in respone handler', function () { it('should pass error to callback', function (done) { var router = Router() - var server = createServer(function hander(req, res, next) { + var server = createServer(function hander (req, res, next) { res.writeHead(200) router(req, res, function (err) { res.end(String(Boolean(err))) @@ -94,16 +94,16 @@ describe('OPTIONS', function () { }) }) -function saw(req, res) { +function saw (req, res) { var msg = 'saw ' + req.method + ' ' + req.url res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) } -function sethit(num) { +function sethit (num) { var name = 'x-fn-' + String(num) - return function hit(req, res, next) { + return function hit (req, res, next) { res.setHeader(name, 'hit') next() } diff --git a/test/fqdn-url.js b/test/fqdn-url.js index 7fc0b71..3ad73b3 100644 --- a/test/fqdn-url.js +++ b/test/fqdn-url.js @@ -57,15 +57,15 @@ describe('FQDN url', function () { }) }) -function setsaw(num) { +function setsaw (num) { var name = 'x-saw-' + String(num) - return function hit(req, res, next) { + return function hit (req, res, next) { res.setHeader(name, req.method + ' ' + req.url) next() } } -function saw(req, res) { +function saw (req, res) { var msg = 'saw ' + req.method + ' ' + req.url res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') diff --git a/test/param.js b/test/param.js index 7a31a3c..43245fc 100644 --- a/test/param.js +++ b/test/param.js @@ -37,7 +37,7 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.param('id', function parseId(req, res, next, val) { + router.param('id', function parseId (req, res, next, val) { req.params.id = Number(val) next() }) @@ -60,12 +60,12 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.param('id', function parseId(req, res, next, val) { + router.param('id', function parseId (req, res, next, val) { req.params.id = Number(val) next() }) - router.param('id', function parseId(req, res, next, val) { + router.param('id', function parseId (req, res, next, val) { req.itemId = Number(val) next() }) @@ -84,7 +84,7 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.param('user', function parseUser(req, res, next, user) { + router.param('user', function parseUser (req, res, next, user) { req.user = user next() }) @@ -103,7 +103,7 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.param('user', function parseUser(req, res, next, user) { + router.param('user', function parseUser (req, res, next, user) { req.user = user next() }) @@ -123,12 +123,12 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.param('id', function parseId(req, res, next, val) { + router.param('id', function parseId (req, res, next, val) { res.setHeader('x-id', val) next() }) - router.param('user', function parseUser(req, res, next, user) { + router.param('user', function parseUser (req, res, next, user) { throw new Error('boom') }) @@ -149,7 +149,7 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.param('user', function parseUser(req, res, next, user) { + router.param('user', function parseUser (req, res, next, user) { req.count = (req.count || 0) + 1 req.user = user next() @@ -171,7 +171,7 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.param('id', function parseUser(req, res, next, val) { + router.param('id', function parseUser (req, res, next, val) { req.count = (req.count || 0) + 1 req.params.id = Number(val) next() @@ -195,7 +195,7 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.param('user', function parseUser(req, res, next, user) { + router.param('user', function parseUser (req, res, next, user) { req.count = (req.count || 0) + 1 req.user = user req.vals = (req.vals || []).concat(user) @@ -218,7 +218,7 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.param('user', function parseUser(req, res, next, user) { + router.param('user', function parseUser (req, res, next, user) { throw new Error('boom') }) @@ -236,11 +236,11 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.param('user', function parseUser(req, res, next, user) { + router.param('user', function parseUser (req, res, next, user) { process.nextTick(next) }) - router.param('user', function parseUser(req, res, next, user) { + router.param('user', function parseUser (req, res, next, user) { throw new Error('boom') }) @@ -260,7 +260,7 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.param('id', function parseId(req, res, next, val) { + router.param('id', function parseId (req, res, next, val) { var id = Number(val) if (isNaN(id)) { @@ -299,7 +299,7 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.param('user', function parseUser(req, res, next, user) { + router.param('user', function parseUser (req, res, next, user) { req.count = (req.count || 0) + 1 req.user = user req.vals = (req.vals || []).concat(user) @@ -323,15 +323,15 @@ describe('Router', function () { }) }) -function sethit(num) { +function sethit (num) { var name = 'x-fn-' + String(num) - return function hit(req, res, next) { + return function hit (req, res, next) { res.setHeader(name, 'hit') next() } } -function saw(req, res) { +function saw (req, res) { var msg = 'saw ' + req.method + ' ' + req.url res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') diff --git a/test/req.params.js b/test/req.params.js index 9a8ade9..334b805 100644 --- a/test/req.params.js +++ b/test/req.params.js @@ -37,7 +37,7 @@ describe('req.params', function () { it('should overwrite value outside the router', function (done) { var router = Router() var server = createServer(function (req, res, next) { - req.params = {'foo': 'bar'} + req.params = { foo: 'bar' } router(req, res, done) }) @@ -51,7 +51,7 @@ describe('req.params', function () { it('should restore previous value outside the router', function (done) { var router = Router() var server = createServer(function (req, res, next) { - req.params = {'foo': 'bar'} + req.params = { foo: 'bar' } router(req, res, function (err) { if (err) return next(err) @@ -71,7 +71,7 @@ describe('req.params', function () { it('should merge outsite object with params', function (done) { var router = Router({ mergeParams: true }) var server = createServer(function (req, res, next) { - req.params = {'foo': 'bar'} + req.params = { foo: 'bar' } router(req, res, function (err) { if (err) return next(err) @@ -109,7 +109,7 @@ describe('req.params', function () { it('should overwrite outside keys that are the same', function (done) { var router = Router({ mergeParams: true }) var server = createServer(function (req, res, next) { - req.params = {'foo': 'bar'} + req.params = { foo: 'bar' } router(req, res, function (err) { if (err) return next(err) @@ -129,7 +129,7 @@ describe('req.params', function () { it('should merge numeric properies by offsetting', function (done) { var router = Router({ mergeParams: true }) var server = createServer(function (req, res, next) { - req.params = {'0': 'foo', '1': 'bar'} + req.params = { 0: 'foo', 1: 'bar' } router(req, res, function (err) { if (err) return next(err) @@ -148,7 +148,7 @@ describe('req.params', function () { it('should merge with same numeric properties', function (done) { var router = Router({ mergeParams: true }) var server = createServer(function (req, res, next) { - req.params = {'0': 'foo'} + req.params = { 0: 'foo' } router(req, res, function (err) { if (err) return next(err) @@ -167,15 +167,15 @@ describe('req.params', function () { }) }) -function hitParams(num) { +function hitParams (num) { var name = 'x-params-' + String(num) - return function hit(req, res, next) { + return function hit (req, res, next) { res.setHeader(name, JSON.stringify(req.params)) next() } } -function sawParams(req, res) { +function sawParams (req, res) { res.statusCode = 200 res.setHeader('Content-Type', 'application/json') res.end(JSON.stringify(req.params)) diff --git a/test/route.js b/test/route.js index 6aa96b2..69dd5ac 100644 --- a/test/route.js +++ b/test/route.js @@ -82,6 +82,8 @@ describe('Router', function () { var route = router.route('/foo') var server = createServer(router) + assert.ok(route) + request(server) .get('/foo') .expect(404, cb) @@ -96,8 +98,8 @@ describe('Router', function () { var route = router.route('/foo') var server = createServer(router) - route.all(function handleError(err, req, res, next) { - throw new Error('boom!') + route.all(function handleError (err, req, res, next) { + throw err || new Error('boom!') }) request(server) @@ -207,8 +209,7 @@ describe('Router', function () { route[method](helloWorld) - request(server) - [method]('/') + request(server)[method]('/') .expect(200) .expect(body) .end(done) @@ -239,8 +240,7 @@ describe('Router', function () { route[method](createHitHandle(1), createHitHandle(2), helloWorld) - request(server) - [method]('/foo') + request(server)[method]('/foo') .expect(200) .expect('x-fn-1', 'hit') .expect('x-fn-2', 'hit') @@ -270,8 +270,7 @@ describe('Router', function () { route[method]([[createHitHandle(1), createHitHandle(2)], createHitHandle(3)], helloWorld) - request(server) - [method]('/foo') + request(server)[method]('/foo') .expect(200) .expect('x-fn-1', 'hit') .expect('x-fn-2', 'hit') @@ -288,13 +287,13 @@ describe('Router', function () { var route = router.route('/foo') var server = createServer(router) - route.all(function createError(req, res, next) { + route.all(function createError (req, res, next) { next(new Error('boom!')) }) route.all(helloWorld) - route.all(function handleError(err, req, res, next) { + route.all(function handleError (err, req, res, next) { res.statusCode = 500 res.end('caught: ' + err.message) }) @@ -309,13 +308,13 @@ describe('Router', function () { var route = router.route('/foo') var server = createServer(router) - route.all(function createError(req, res, next) { + route.all(function createError (req, res, next) { throw new Error('boom!') }) route.all(helloWorld) - route.all(function handleError(err, req, res, next) { + route.all(function handleError (err, req, res, next) { res.statusCode = 500 res.end('caught: ' + err.message) }) @@ -330,22 +329,22 @@ describe('Router', function () { var route = router.route('/foo') var server = createServer(router) - route.all(function createError(req, res, next) { + route.all(function createError (req, res, next) { throw new Error('boom!') }) - route.all(function handleError(err, req, res, next) { - throw new Error('oh, no!') + route.all(function handleError (err, req, res, next) { + throw new Error('ouch: ' + err.message) }) - route.all(function handleError(err, req, res, next) { + route.all(function handleError (err, req, res, next) { res.statusCode = 500 res.end('caught: ' + err.message) }) request(server) .get('/foo') - .expect(500, 'caught: oh, no!', done) + .expect(500, 'caught: ouch: boom!', done) }) }) @@ -418,7 +417,7 @@ describe('Router', function () { next('route') }) - route.all(function handleError(err, req, res, next) { + route.all(function handleError (err, req, res, next) { res.statusCode = 500 res.end('caught: ' + err.message) }) @@ -507,7 +506,7 @@ describe('Router', function () { var server = createServer(router) route.all(function createError (req, res, next) { - return Promise.reject() + return Promise.reject() // eslint-disable-line prefer-promise-reject-errors }) route.all(helloWorld) @@ -575,7 +574,8 @@ describe('Router', function () { }) route.all(function handleError (err, req, res, next) { - return Promise.reject() + assert.equal(err.message, 'boom!') + return Promise.reject() // eslint-disable-line prefer-promise-reject-errors }) route.all(function handleError (err, req, res, next) { @@ -625,7 +625,7 @@ describe('Router', function () { request(server) .get('/bar') - .expect(200, {'foo': 'bar'}, done) + .expect(200, { foo: 'bar' }, done) }) it('should match single path segment', function (done) { @@ -649,7 +649,7 @@ describe('Router', function () { request(server) .get('/fizz/buzz') - .expect(200, {'foo': 'fizz', 'bar': 'buzz'}, done) + .expect(200, { foo: 'fizz', bar: 'buzz' }, done) }) it('should work following a partial capture group', function (done) { @@ -678,7 +678,7 @@ describe('Router', function () { request(server) .get('/tj(edit)') - .expect(200, {'user': 'tj', 'op': 'edit'}, done) + .expect(200, { user: 'tj', op: 'edit' }, done) }) it('should work within arrays', function (done) { @@ -691,11 +691,11 @@ describe('Router', function () { request(server) .get('/user/tj/poke') - .expect(200, {'user': 'tj'}, cb) + .expect(200, { user: 'tj' }, cb) request(server) .get('/user/tj/pokes') - .expect(200, {'user': 'tj'}, cb) + .expect(200, { user: 'tj' }, cb) }) }) @@ -826,28 +826,20 @@ describe('Router', function () { }) }) -function helloWorld(req, res) { +function helloWorld (req, res) { res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end('hello, world') } -function setsaw(num) { - var name = 'x-saw-' + String(num) - return function hit(req, res, next) { - res.setHeader(name, req.method + ' ' + req.url) - next() - } -} - -function saw(req, res) { +function saw (req, res) { var msg = 'saw ' + req.method + ' ' + req.url res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) } -function sendParams(req, res) { +function sendParams (req, res) { res.statusCode = 200 res.setHeader('Content-Type', 'application/json') res.end(JSON.stringify(req.params)) diff --git a/test/router.js b/test/router.js index f8acd18..74308f7 100644 --- a/test/router.js +++ b/test/router.js @@ -59,8 +59,7 @@ describe('Router', function () { ? shouldHaveBody(Buffer.from('hello, world')) : shouldNotHaveBody() - request(server) - [method]('/') + request(server)[method]('/') .expect(200) .expect(body) .end(cb) @@ -283,8 +282,7 @@ describe('Router', function () { router[method]('/', helloWorld) - request(server) - [method]('/') + request(server)[method]('/') .expect(200) .expect(body) .end(done) @@ -302,21 +300,18 @@ describe('Router', function () { router[method](['/foo', '/bar'], createHitHandle(1), helloWorld) - request(server) - [method]('/') + request(server)[method]('/') .expect(404) .expect(shouldNotHitHandle(1)) .end(cb) - request(server) - [method]('/foo') + request(server)[method]('/foo') .expect(200) .expect(shouldHitHandle(1)) .expect(body) .end(cb) - request(server) - [method]('/bar') + request(server)[method]('/bar') .expect(200) .expect(shouldHitHandle(1)) .expect(body) @@ -330,21 +325,18 @@ describe('Router', function () { router[method](/^\/[a-z]oo$/, createHitHandle(1), helloWorld) - request(server) - [method]('/') + request(server)[method]('/') .expect(404) .expect(shouldNotHitHandle(1)) .end(cb) - request(server) - [method]('/foo') + request(server)[method]('/foo') .expect(200) .expect(shouldHitHandle(1)) .expect(body) .end(cb) - request(server) - [method]('/zoo') + request(server)[method]('/zoo') .expect(200) .expect(shouldHitHandle(1)) .expect(body) @@ -358,28 +350,24 @@ describe('Router', function () { router[method]('/:thing', createHitHandle(1), helloWorld) - request(server) - [method]('/') + request(server)[method]('/') .expect(404) .expect(shouldNotHitHandle(1)) .end(cb) - request(server) - [method]('/foo') + request(server)[method]('/foo') .expect(200) .expect(shouldHitHandle(1)) .expect(body) .end(cb) - request(server) - [method]('/bar') + request(server)[method]('/bar') .expect(200) .expect(shouldHitHandle(1)) .expect(body) .end(cb) - request(server) - [method]('/foo/bar') + request(server)[method]('/foo/bar') .expect(404) .expect(shouldNotHitHandle(1)) .end(cb) @@ -391,8 +379,7 @@ describe('Router', function () { router[method]('/', createHitHandle(1), createHitHandle(2), helloWorld) - request(server) - [method]('/') + request(server)[method]('/') .expect(200) .expect(shouldHitHandle(1)) .expect(shouldHitHandle(2)) @@ -405,13 +392,12 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router[method]('/foo', function handle(req, res) { + router[method]('/foo', function handle (req, res) { res.setHeader('x-url-base', JSON.stringify(req.baseUrl)) res.end() }) - request(server) - [method]('/foo') + request(server)[method]('/foo') .expect('x-url-base', '""') .expect(200, done) }) @@ -422,13 +408,12 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router[method]('/foo', function handle(req, res) { + router[method]('/foo', function handle (req, res) { res.setHeader('x-is-route', String(req.route instanceof Router.Route)) res.end() }) - request(server) - [method]('/foo') + request(server)[method]('/foo') .expect('x-is-route', 'true') .expect(200, done) }) @@ -437,13 +422,12 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router[method]('/foo', function handle(req, res) { + router[method]('/foo', function handle (req, res) { res.setHeader('x-is-route', String(req.route.path === '/foo')) res.end() }) - request(server) - [method]('/foo') + request(server)[method]('/foo') .expect('x-is-route', 'true') .expect(200, done) }) @@ -501,7 +485,7 @@ describe('Router', function () { it('should not invoke for blank URLs', function (done) { var router = new Router() - var server = createServer(function hander(req, res, next) { + var server = createServer(function hander (req, res, next) { req.url = '' router(req, res, next) }) @@ -570,8 +554,8 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.use(function handleError(err, req, res, next) { - throw new Error('boom!') + router.use(function handleError (err, req, res, next) { + throw err || new Error('boom!') }) request(server) @@ -584,7 +568,7 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.use(function handle(req, res, next) { + router.use(function handle (req, res, next) { next(new Error('boom!')) }) @@ -599,7 +583,7 @@ describe('Router', function () { var router = new Router() var server = createServer(router) - router.use(function handle(req, res, next) { + router.use(function handle (req, res, next) { throw new Error('boom!') }) @@ -616,7 +600,7 @@ describe('Router', function () { router.use(sawError) - router.use(function handle(req, res, next) { + router.use(function handle (req, res, next) { throw new Error('boom!') }) @@ -740,7 +724,7 @@ describe('Router', function () { var server = createServer(router) router.use(function createError (req, res, next) { - return Promise.reject() + return Promise.reject() // eslint-disable-line prefer-promise-reject-errors }) router.use(sawError) @@ -793,7 +777,7 @@ describe('Router', function () { var server = createServer(router) router.use(function createError (req, res, next) { - return Promise.reject() + return Promise.reject() // eslint-disable-line prefer-promise-reject-errors }) router.use(function handleError (err, req, res, next) { @@ -1168,7 +1152,7 @@ describe('Router', function () { .expect(200, 'saw /foo/bar', done) }) - it('should be altered correctly', function(done){ + it('should be altered correctly', function (done) { var router = new Router() var server = createServer(router) var sub1 = new Router() @@ -1289,43 +1273,43 @@ describe('Router', function () { }) }) -function helloWorld(req, res) { +function helloWorld (req, res) { res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end('hello, world') } -function setsaw(num) { +function setsaw (num) { var name = 'x-saw-' + String(num) - return function saw(req, res, next) { + return function saw (req, res, next) { res.setHeader(name, req.method + ' ' + req.url) next() } } -function setsawBase(num) { +function setsawBase (num) { var name = 'x-saw-base-' + String(num) - return function sawBase(req, res, next) { + return function sawBase (req, res, next) { res.setHeader(name, String(req.baseUrl)) next() } } -function saw(req, res) { +function saw (req, res) { var msg = 'saw ' + req.method + ' ' + req.url res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) } -function sawError(err, req, res, next) { +function sawError (err, req, res, next) { var msg = 'saw ' + err.name + ': ' + err.message res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) } -function sawBase(req, res) { +function sawBase (req, res) { var msg = 'saw ' + req.baseUrl res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') diff --git a/test/support/utils.js b/test/support/utils.js index 56cfe94..30b2a5e 100644 --- a/test/support/utils.js +++ b/test/support/utils.js @@ -16,21 +16,21 @@ exports.shouldNotHaveBody = shouldNotHaveBody exports.shouldHitHandle = shouldHitHandle exports.shouldNotHitHandle = shouldNotHitHandle -function createHitHandle(num) { +function createHitHandle (num) { var name = 'x-fn-' + String(num) - return function hit(req, res, next) { + return function hit (req, res, next) { res.setHeader(name, 'hit') next() } } -function createServer(router) { - return http.createServer(function onRequest(req, res) { +function createServer (router) { + return http.createServer(function onRequest (req, res) { router(req, res, finalhandler(req, res)) }) } -function rawrequest(server) { +function rawrequest (server) { var _headers = {} var _method var _path @@ -40,7 +40,7 @@ function rawrequest(server) { _test[method] = go.bind(null, method) }) - function expect(status, body, callback) { + function expect (status, body, callback) { if (arguments.length === 2) { _headers[status.toLowerCase()] = body return this @@ -65,12 +65,12 @@ function rawrequest(server) { path: _path, port: port }) - req.on('response', function(res){ + req.on('response', function (res) { var buf = '' res.setEncoding('utf8') - res.on('data', function(s){ buf += s }) - res.on('end', function(){ + res.on('data', function (s) { buf += s }) + res.on('end', function () { var err = null try { @@ -117,7 +117,7 @@ function shouldHaveBody (buf) { } } -function shouldHitHandle(num) { +function shouldHitHandle (num) { var header = 'x-fn-' + String(num) return function (res) { assert.equal(res.headers[header], 'hit', 'should hit handle ' + num) @@ -130,11 +130,11 @@ function shouldNotHaveBody () { } } -function shouldNotHitHandle(num) { +function shouldNotHitHandle (num) { return shouldNotHaveHeader('x-fn-' + String(num)) } -function shouldNotHaveHeader(header) { +function shouldNotHaveHeader (header) { return function (res) { assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header) } From 0b5a0a6b578565cc36712f8d5004566bf5e1472f Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 29 Mar 2020 23:38:36 -0400 Subject: [PATCH 044/207] Remove debug dependency --- HISTORY.md | 1 + index.js | 8 -------- lib/layer.js | 2 -- lib/route.js | 4 ---- package.json | 1 - 5 files changed, 1 insertion(+), 15 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 40c9d4e..b0b3517 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ This incorporates all changes after 1.3.3 up to 1.3.5. * Internalize private `router.process_params` method + * Remove `debug` dependency * deps: array-flatten@3.0.0 * deps: parseurl@~1.3.3 * deps: path-to-regexp@3.2.0 diff --git a/index.js b/index.js index dc71423..45495b3 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,6 @@ * @private */ -var debug = require('debug')('router') var flatten = require('array-flatten').flatten var Layer = require('./lib/layer') var methods = require('methods') @@ -150,8 +149,6 @@ Router.prototype.handle = function handle (req, res, callback) { throw new TypeError('argument callback is required') } - debug('dispatching %s %s', req.method, req.url) - var idx = 0 var methods var protohost = getProtohost(req.url) || '' @@ -312,7 +309,6 @@ Router.prototype.handle = function handle (req, res, callback) { // Trim off the part of the url that matches the route // middleware (.use stuff) needs to have the path stripped - debug('trim prefix (%s) from url %s', layerPath, req.url) removed = layerPath req.url = protohost + req.url.substr(protohost.length + removed.length) @@ -328,8 +324,6 @@ Router.prototype.handle = function handle (req, res, callback) { : removed) } - debug('%s %s : %s', layer.name, layerPath, req.originalUrl) - if (layerError) { layer.handleError(layerError, req, res, next) } else { @@ -387,8 +381,6 @@ Router.prototype.use = function use (handler) { } // add the middleware - debug('use %o %s', path, fn.name || '') - var layer = new Layer(path, { sensitive: this.caseSensitive, strict: false, diff --git a/lib/layer.js b/lib/layer.js index f6365f9..39acfe2 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -13,7 +13,6 @@ */ var pathRegexp = require('path-to-regexp') -var debug = require('debug')('router:layer') /** * Module variables. @@ -34,7 +33,6 @@ function Layer (path, options, fn) { return new Layer(path, options, fn) } - debug('new %o', path) var opts = options || {} this.handle = fn diff --git a/lib/route.js b/lib/route.js index 28a2266..7656403 100644 --- a/lib/route.js +++ b/lib/route.js @@ -12,7 +12,6 @@ * @private */ -var debug = require('debug')('router:route') var flatten = require('array-flatten').flatten var Layer = require('./layer') var methods = require('methods') @@ -38,7 +37,6 @@ module.exports = Route */ function Route (path) { - debug('new %o', path) this.path = path this.stack = [] @@ -213,8 +211,6 @@ methods.forEach(function (method) { throw new TypeError('argument handler must be a function') } - debug('%s %s', method, this.path) - var layer = Layer('/', {}, fn) layer.method = method diff --git a/package.json b/package.json index 2ce21d2..0935fd8 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "repository": "pillarjs/router", "dependencies": { "array-flatten": "3.0.0", - "debug": "3.1.0", "methods": "~1.1.2", "parseurl": "~1.3.3", "path-to-regexp": "3.2.0", From ca507eebd99820ab13c623df629e64b7707c0dbe Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 29 Mar 2020 23:40:06 -0400 Subject: [PATCH 045/207] 2.0.0-beta.1 --- HISTORY.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index b0b3517..55b18bd 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,5 @@ -2.x -=== +2.0.0-beta.1 / 2020-03-29 +========================= This incorporates all changes after 1.3.3 up to 1.3.5. diff --git a/package.json b/package.json index 0935fd8..9b6306c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "router", "description": "Simple middleware-style router", - "version": "2.0.0-alpha.1", + "version": "2.0.0-beta.1", "author": "Douglas Christopher Wilson ", "contributors": [ "Blake Embrey " From c2af877c794a45615bf14c3f92954e310a3ea852 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 22 Jun 2020 00:04:05 -0400 Subject: [PATCH 046/207] build: Node.js@10.21 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a5dfafe..d9fa210 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ node_js: - "7.10" - "8.17" - "9.11" - - "10.19" + - "10.21" - "11.15" - "12.16" - "13.11" From 35e6a1436b721e74fc25ff0062cd7c2703aa0845 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 22 Jun 2020 00:11:04 -0400 Subject: [PATCH 047/207] build: mocha@7.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0f2bd98..37f30f1 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "7.1.1", + "mocha": "7.2.0", "safe-buffer": "5.2.0", "supertest": "4.0.2" }, From e575e44cc5c8327ad2f39cd0ed263dbb384ca601 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 22 Jun 2020 19:33:18 -0400 Subject: [PATCH 048/207] build: support Node.js 14.x --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index d9fa210..47d1307 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ node_js: - "11.15" - "12.16" - "13.11" + - "14.4" cache: directories: - node_modules From 9fcb097d5e354ba830043ae613a71cf1a211d1fb Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 24 Jun 2020 16:58:36 -0400 Subject: [PATCH 049/207] build: Node.js@13.14 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 47d1307..5d6dfbc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ node_js: - "10.21" - "11.15" - "12.16" - - "13.11" + - "13.14" - "14.4" cache: directories: From b7d571ce2c58115cd7c2ba2dc7eb9d50efdcc2ed Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 24 Jun 2020 17:03:15 -0400 Subject: [PATCH 050/207] build: Node.js@12.18 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5d6dfbc..97360e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ node_js: - "9.11" - "10.21" - "11.15" - - "12.16" + - "12.18" - "13.14" - "14.4" cache: From 233f2b83b6585f13c4ed503cfb09b990c4c609e2 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 9 Jul 2020 19:22:31 -0400 Subject: [PATCH 051/207] build: Node.js@14.10 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 97360e4..7f0cc75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ node_js: - "11.15" - "12.18" - "13.14" - - "14.4" + - "14.10" cache: directories: - node_modules From 5fa7c9c81704f35278283ee9ab3a59eb318161f7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 10 Jul 2020 01:28:21 -0400 Subject: [PATCH 052/207] build: mocha@8.0.1 --- .travis.yml | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7f0cc75..6067c93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -72,6 +72,7 @@ before_install: elif node_version_lt '4.0' ; then npm_use_module 'mocha' '3.5.3' elif node_version_lt '6.0' ; then npm_use_module 'mocha' '5.2.0' elif node_version_lt '8.0' ; then npm_use_module 'mocha' '6.2.2' + elif node_version_lt '10.0'; then npm_use_module 'mocha' '7.2.0' fi - | # Configure supertest for http calls diff --git a/package.json b/package.json index 37f30f1..d99e252 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "7.2.0", + "mocha": "8.0.1", "safe-buffer": "5.2.0", "supertest": "4.0.2" }, From a25d74616a3a6b4b544e772bf54869e8d22e2775 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 11 Jul 2020 18:59:22 -0400 Subject: [PATCH 053/207] build: eslint@7.4.0 --- .travis.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6067c93..97c7cdf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,7 +60,7 @@ before_install: # Setup Node.js version-specific dependencies - | # Configure eslint for linting - if node_version_lt '8.0'; then npm_remove_module_re '^eslint(-|$)' + if node_version_lt '10.0'; then npm_remove_module_re '^eslint(-|$)' fi - | # Configure istanbul for coverage diff --git a/package.json b/package.json index d99e252..56fb3f8 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "6.8.0", + "eslint": "7.4.0", "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", From 823838f5dcfb5f3924820b0d6885962bd5a1a4b4 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 10 Aug 2020 21:51:54 -0400 Subject: [PATCH 054/207] build: mocha@8.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 56fb3f8..a1ea463 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "8.0.1", + "mocha": "8.1.1", "safe-buffer": "5.2.0", "supertest": "4.0.2" }, From 897dd685ff8fa8575cbc33e546d4a8c0721960d4 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 1 Sep 2020 23:44:10 -0400 Subject: [PATCH 055/207] build: eslint@7.8.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a1ea463..82734fe 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "7.4.0", + "eslint": "7.8.0", "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", From 911bd11c832b584d63cc8aa4573df347e48d8805 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Sep 2020 00:02:24 -0400 Subject: [PATCH 056/207] build: mocha@8.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 82734fe..852e18d 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "8.1.1", + "mocha": "8.1.3", "safe-buffer": "5.2.0", "supertest": "4.0.2" }, From 3b71a1f09a5a46fbbe2eb5ee063cd1678dde98ff Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Sep 2020 00:07:31 -0400 Subject: [PATCH 057/207] build: Node.js@10.22 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 97c7cdf..7b94205 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ node_js: - "7.10" - "8.17" - "9.11" - - "10.21" + - "10.22" - "11.15" - "12.18" - "13.14" From 230dd8f671521adea09358a805358b5b0274eb9e Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 20 Oct 2020 19:33:49 -0400 Subject: [PATCH 058/207] build: Node.js@14.11 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7b94205..f67265b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ node_js: - "11.15" - "12.18" - "13.14" - - "14.10" + - "14.11" cache: directories: - node_modules From fc70d6ff53674f92dad203ea8d16407141ff5178 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 21 Oct 2020 20:03:12 -0400 Subject: [PATCH 059/207] build: support Node.js 15.x --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index f67265b..d2af64b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ node_js: - "12.18" - "13.14" - "14.11" + - "15.0" cache: directories: - node_modules From 3327211677e3725ce5426e8294032fdd2ec8cc3e Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 21 Oct 2020 20:07:42 -0400 Subject: [PATCH 060/207] build: mocha@8.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 852e18d..ea8837d 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "8.1.3", + "mocha": "8.2.0", "safe-buffer": "5.2.0", "supertest": "4.0.2" }, From a5dcda228e53583c162bbd7b2b55c7ab62f00307 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 27 Oct 2020 18:31:26 -0400 Subject: [PATCH 061/207] build: eslint@7.12.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ea8837d..40733e2 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "7.8.0", + "eslint": "7.12.0", "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", From 85aca8cd22e28c896b4345a62e5d3ae8aa998c37 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 27 Oct 2020 18:35:03 -0400 Subject: [PATCH 062/207] build: Node.js@14.15 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d2af64b..b2d2709 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ node_js: - "11.15" - "12.18" - "13.14" - - "14.11" + - "14.15" - "15.0" cache: directories: From 48a0cea6bb93ef9f4a8a66fb1a5e005e9fd895c7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 28 Oct 2020 01:22:00 -0400 Subject: [PATCH 063/207] build: Node.js@10.23 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b2d2709..a1e5272 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ node_js: - "7.10" - "8.17" - "9.11" - - "10.22" + - "10.23" - "11.15" - "12.18" - "13.14" From 1b629c88ceccfb71ca39b5e9f592f746122b67b8 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 31 Oct 2020 19:21:24 -0400 Subject: [PATCH 064/207] build: Node.js@12.19 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a1e5272..7e14546 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ node_js: - "9.11" - "10.23" - "11.15" - - "12.18" + - "12.19" - "13.14" - "14.15" - "15.0" From 9b8823386cca5f87a89b062becbe0dc10c1fe4b5 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 16 Nov 2020 17:22:11 -0500 Subject: [PATCH 065/207] build: Node.js@15.2 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7e14546..19ff521 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ node_js: - "12.19" - "13.14" - "14.15" - - "15.0" + - "15.2" cache: directories: - node_modules From 400fd73f9401af33280a1f5108fd713d086b666b Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 16 Nov 2020 17:28:45 -0500 Subject: [PATCH 066/207] build: eslint@7.13.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 40733e2..d5172a7 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "7.12.0", + "eslint": "7.13.0", "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", From 79cf93562aeda07c7e9410f2586e560f09e37dd2 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 17 Nov 2020 00:32:53 -0500 Subject: [PATCH 067/207] build: mocha@8.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d5172a7..e088b64 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "8.2.0", + "mocha": "8.2.1", "safe-buffer": "5.2.0", "supertest": "4.0.2" }, From a88d7b0fbc93b306f0d9fe9d8c87bac3203304c5 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 17 Nov 2020 19:48:43 -0500 Subject: [PATCH 068/207] build: supertest@5.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e088b64..26d74fa 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "istanbul": "0.4.5", "mocha": "8.2.1", "safe-buffer": "5.2.0", - "supertest": "4.0.2" + "supertest": "5.0.0" }, "files": [ "lib/", From d9f050d7d581a4407b71a1ce137e01c50c8179c6 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 8 Dec 2020 21:10:53 -0500 Subject: [PATCH 069/207] build: Node.js@15.3 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 19ff521..58410f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ node_js: - "12.19" - "13.14" - "14.15" - - "15.2" + - "15.3" cache: directories: - node_modules From c20c9bd69f0af3b6dd57d9ff360c7187738d3133 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 8 Dec 2020 21:12:30 -0500 Subject: [PATCH 070/207] build: Node.js@12.20 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 58410f4..e08af2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ node_js: - "9.11" - "10.23" - "11.15" - - "12.19" + - "12.20" - "13.14" - "14.15" - "15.3" From 7b786cd5093b8e136ff05b26e1e901320a451343 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 9 Dec 2020 00:02:55 -0500 Subject: [PATCH 071/207] build: eslint@7.15.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 26d74fa..ec6a348 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "7.13.0", + "eslint": "7.15.0", "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", From 2ece61d1688fef33e6d83a79cc3774d9ab957bf8 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 9 Dec 2020 00:09:36 -0500 Subject: [PATCH 072/207] build: supertest@6.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ec6a348..907a69f 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "istanbul": "0.4.5", "mocha": "8.2.1", "safe-buffer": "5.2.0", - "supertest": "5.0.0" + "supertest": "6.0.1" }, "files": [ "lib/", From d2f6db84c9969c35defc9e1c203029ccfa882cc6 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 12 Jan 2021 23:54:36 -0500 Subject: [PATCH 073/207] build: Node.js@15.6 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e08af2b..b8c76fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ node_js: - "12.20" - "13.14" - "14.15" - - "15.3" + - "15.6" cache: directories: - node_modules From ebf4abbeb99cf8a2613cc493831d6157416459bd Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 13 Jan 2021 00:25:10 -0500 Subject: [PATCH 074/207] build: eslint@7.17.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 907a69f..cd9e7c9 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "7.15.0", + "eslint": "7.17.0", "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", From 15a60312db7e5fb331270c846436b073709e0b9f Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 13 Jan 2021 00:31:07 -0500 Subject: [PATCH 075/207] deps: safe-buffer@5.2.1 --- HISTORY.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 1000457..322ef5e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * deps: safe-buffer@5.2.1 + 1.3.5 / 2020-03-24 ================== diff --git a/package.json b/package.json index cd9e7c9..2bd025d 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "finalhandler": "1.1.2", "istanbul": "0.4.5", "mocha": "8.2.1", - "safe-buffer": "5.2.0", + "safe-buffer": "5.2.1", "supertest": "6.0.1" }, "files": [ From d07d28ce7e6bd8788e2d8c1a7a009792d9182ff3 Mon Sep 17 00:00:00 2001 From: Rodion Abdurakhimov Date: Wed, 25 Nov 2020 10:15:07 +0200 Subject: [PATCH 076/207] docs: fix typo in code example closes #98 closes #97 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6be6155..591fd60 100644 --- a/README.md +++ b/README.md @@ -321,7 +321,7 @@ handler.get('/', function (req, res) { res.setHeader('Content-Type', 'text/plain; charset=utf-8') // will respond with the param of the router's parent route - res.end(path + '\n') + res.end(req.params.path + '\n') }) // make our http server listen to connections From 22feb335df9137bd6a76812b8276d943ce39322d Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 23 Jan 2021 23:17:35 -0500 Subject: [PATCH 077/207] build: supertest@6.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2bd025d..df5ea68 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "istanbul": "0.4.5", "mocha": "8.2.1", "safe-buffer": "5.2.1", - "supertest": "6.0.1" + "supertest": "6.1.1" }, "files": [ "lib/", From f68ab38de341e883ace8ca5f172ee68d1b1f0deb Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 1 Feb 2021 19:32:24 -0500 Subject: [PATCH 078/207] build: Node.js@15.7 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b8c76fd..6299b68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ node_js: - "12.20" - "13.14" - "14.15" - - "15.6" + - "15.7" cache: directories: - node_modules From 511a375a6ba3fffe10c13b1da094cc923bb6e11d Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 1 Mar 2021 20:41:34 -0500 Subject: [PATCH 079/207] build: eslint@7.21.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index df5ea68..a94f600 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "7.17.0", + "eslint": "7.21.0", "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", From 12de6bedf779120bfa3ee27ec409e341aa62d867 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 4 Mar 2021 19:33:30 -0500 Subject: [PATCH 080/207] build: Node.js@12.21 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6299b68..4308b38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ node_js: - "9.11" - "10.23" - "11.15" - - "12.20" + - "12.21" - "13.14" - "14.15" - "15.7" From ddf17c2d776fb7ddfc5fb6d58601612f1ea53e1a Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 5 Mar 2021 01:22:12 -0500 Subject: [PATCH 081/207] build: Node.js@14.16 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4308b38..9111bff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ node_js: - "11.15" - "12.21" - "13.14" - - "14.15" + - "14.16" - "15.7" cache: directories: From a7959381269fb8f4142b72efff528de1159b5362 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 5 Mar 2021 01:29:08 -0500 Subject: [PATCH 082/207] build: mocha@8.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a94f600..207c1fe 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "1.0.2", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "8.2.1", + "mocha": "8.3.0", "safe-buffer": "5.2.1", "supertest": "6.1.1" }, From 91476193accf19a1b40fbd072cfe4f9bf518907c Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 6 Mar 2021 21:22:58 -0500 Subject: [PATCH 083/207] build: Node.js@10.24 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9111bff..7f26f7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ node_js: - "7.10" - "8.17" - "9.11" - - "10.23" + - "10.24" - "11.15" - "12.21" - "13.14" From d6a357aca530be32034de99202a83ae5b707ff89 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 7 Mar 2021 23:08:06 -0500 Subject: [PATCH 084/207] build: eslint-plugin-markdown@2.0.0 --- .eslintrc | 8 -------- .eslintrc.yml | 18 ++++++++++++++++++ package.json | 4 ++-- 3 files changed, 20 insertions(+), 10 deletions(-) delete mode 100644 .eslintrc create mode 100644 .eslintrc.yml diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 07eb965..0000000 --- a/.eslintrc +++ /dev/null @@ -1,8 +0,0 @@ -{ - "rules": { - "eol-last": "error", - "indent": ["error", 2, { "SwitchCase": 1 }], - "no-trailing-spaces": "error", - "semi": ["error", "never"] - } -} diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..241439a --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,18 @@ +root: true +extends: + - plugin:markdown/recommended +plugins: + - markdown +overrides: + - files: '**/*.md' + processor: 'markdown/markdown' +rules: + eol-last: error + indent: + - error + - 2 + - SwitchCase: 1 + no-trailing-spaces: error + semi: + - error + - never diff --git a/package.json b/package.json index 207c1fe..0f35f56 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "devDependencies": { "after": "0.8.2", "eslint": "7.21.0", - "eslint-plugin-markdown": "1.0.2", + "eslint-plugin-markdown": "2.0.0", "finalhandler": "1.1.2", "istanbul": "0.4.5", "mocha": "8.3.0", @@ -38,7 +38,7 @@ "node": ">= 0.8" }, "scripts": { - "lint": "eslint --plugin markdown --ext js,md .", + "lint": "eslint .", "test": "mocha --reporter spec --bail --check-leaks test/", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/", From 5410d765667f4317c4bb15c95112fd9852bc02be Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 7 Mar 2021 23:27:04 -0500 Subject: [PATCH 085/207] build: Node.js@15.11 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7f26f7a..bc3ea2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ node_js: - "12.21" - "13.14" - "14.16" - - "15.7" + - "15.11" cache: directories: - node_modules From 9c2000dbb8750bed4ba75552667aa3b1dae6673d Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 18 Mar 2021 17:38:25 -0400 Subject: [PATCH 086/207] build: mocha@8.3.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0f35f56..066da6a 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "2.0.0", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "8.3.0", + "mocha": "8.3.2", "safe-buffer": "5.2.1", "supertest": "6.1.1" }, From e1eceec0529960023d158c4d92882111fc1684a8 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 18 Mar 2021 18:08:17 -0400 Subject: [PATCH 087/207] build: Node.js@15.12 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bc3ea2c..b443bea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ node_js: - "12.21" - "13.14" - "14.16" - - "15.11" + - "15.12" cache: directories: - node_modules From daa8b535eda7520811149fe8136a5028b1c4a7d4 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 19 Mar 2021 01:22:24 -0400 Subject: [PATCH 088/207] build: supertest@6.1.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 066da6a..88893ee 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "istanbul": "0.4.5", "mocha": "8.3.2", "safe-buffer": "5.2.1", - "supertest": "6.1.1" + "supertest": "6.1.3" }, "files": [ "lib/", From 5c3c62fb289406fa924465df543f05dc75c79ef7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 4 Apr 2021 15:38:47 -0400 Subject: [PATCH 089/207] build: eslint@7.23.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 88893ee..510d9cb 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "7.21.0", + "eslint": "7.23.0", "eslint-plugin-markdown": "2.0.0", "finalhandler": "1.1.2", "istanbul": "0.4.5", From 160baac0fff5daae542ad335ce554bc1537a3d7b Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 4 Apr 2021 15:46:55 -0400 Subject: [PATCH 090/207] build: Node.js@15.13 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b443bea..ae00b65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ node_js: - "12.21" - "13.14" - "14.16" - - "15.12" + - "15.13" cache: directories: - node_modules From 7c43278e72f935ae7c5e2a13232ab2902bed3772 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 6 Apr 2021 17:49:25 -0400 Subject: [PATCH 091/207] build: eslint-plugin-markdown@2.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 510d9cb..61fdbdb 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "devDependencies": { "after": "0.8.2", "eslint": "7.23.0", - "eslint-plugin-markdown": "2.0.0", + "eslint-plugin-markdown": "2.0.1", "finalhandler": "1.1.2", "istanbul": "0.4.5", "mocha": "8.3.2", From 579aa7858f402e7cd385379cf6aa2eddeacad741 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 6 Apr 2021 17:56:53 -0400 Subject: [PATCH 092/207] build: Node.js@12.22 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ae00b65..9bf905c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ node_js: - "9.11" - "10.24" - "11.15" - - "12.21" + - "12.22" - "13.14" - "14.16" - "15.13" From 1e9d9855c7273d6f1076f6dcbca5b88e0c0d3182 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 6 Apr 2021 18:02:13 -0400 Subject: [PATCH 093/207] build: Node.js@15.14 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9bf905c..16ab52d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ node_js: - "12.22" - "13.14" - "14.16" - - "15.13" + - "15.14" cache: directories: - node_modules From 089ba6f5c4f61b286d401c816244b842cc18e15e Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 18 Apr 2021 20:31:16 -0400 Subject: [PATCH 094/207] build: eslint@7.24.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 61fdbdb..4864987 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "7.23.0", + "eslint": "7.24.0", "eslint-plugin-markdown": "2.0.1", "finalhandler": "1.1.2", "istanbul": "0.4.5", From 2c1a96eba9db28130a8cd8efaff6587feb3ffdec Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 14 May 2021 15:49:10 -0400 Subject: [PATCH 095/207] build: Node.js@14.17 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 16ab52d..edd2908 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ node_js: - "11.15" - "12.22" - "13.14" - - "14.16" + - "14.17" - "15.14" cache: directories: From 0c7e9b201951b0a6f24e4dcc286c725b722430e6 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 14 May 2021 15:56:10 -0400 Subject: [PATCH 096/207] build: support Node.js 16.x --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index edd2908..fa1043c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ node_js: - "13.14" - "14.17" - "15.14" + - "16.1" cache: directories: - node_modules From b4aa9f6f78bb459ef8cd7c1f37a72d029c621ed1 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 14 May 2021 16:18:29 -0400 Subject: [PATCH 097/207] build: eslint@7.26.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4864987..92d47f0 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "7.24.0", + "eslint": "7.26.0", "eslint-plugin-markdown": "2.0.1", "finalhandler": "1.1.2", "istanbul": "0.4.5", From 64ef7594155f35b2de31ea080ff3f6c0471de32f Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 16 May 2021 17:38:32 -0400 Subject: [PATCH 098/207] build: mocha@8.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 92d47f0..f976f07 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "eslint-plugin-markdown": "2.0.1", "finalhandler": "1.1.2", "istanbul": "0.4.5", - "mocha": "8.3.2", + "mocha": "8.4.0", "safe-buffer": "5.2.1", "supertest": "6.1.3" }, From 7be0e0442bec0db43ba5ae1b35eab4d14175b79d Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 16 May 2021 17:49:07 -0400 Subject: [PATCH 099/207] build: eslint-plugin-markdown@2.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f976f07..d80bfc6 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "devDependencies": { "after": "0.8.2", "eslint": "7.26.0", - "eslint-plugin-markdown": "2.0.1", + "eslint-plugin-markdown": "2.1.0", "finalhandler": "1.1.2", "istanbul": "0.4.5", "mocha": "8.4.0", From 4b5db127545bf6264e14eecde4597f34860ad05e Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 17 May 2021 11:15:22 -0400 Subject: [PATCH 100/207] build: use nyc for test coverage --- .gitignore | 1 + .travis.yml | 19 +++++++++++-------- package.json | 6 +++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 0fa6951..f15b98e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.nyc_output/ coverage/ node_modules/ npm-debug.log diff --git a/.travis.yml b/.travis.yml index fa1043c..a771aa4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,10 +64,6 @@ before_install: # Configure eslint for linting if node_version_lt '10.0'; then npm_remove_module_re '^eslint(-|$)' fi - - | - # Configure istanbul for coverage - if node_version_lt '0.10'; then npm_remove_module_re '^istanbul$' - fi - | # Configure mocha for testing if node_version_lt '0.10'; then npm_use_module 'mocha' '2.5.3' @@ -76,6 +72,13 @@ before_install: elif node_version_lt '8.0' ; then npm_use_module 'mocha' '6.2.2' elif node_version_lt '10.0'; then npm_use_module 'mocha' '7.2.0' fi + - | + # Configure nyc for coverage + if node_version_lt '0.10'; then npm_remove_module_re '^nyc$' + elif node_version_lt '4.0' ; then npm_use_module 'nyc' '10.3.2' + elif node_version_lt '6.0' ; then npm_use_module 'nyc' '11.9.0' + elif node_version_lt '8.0' ; then npm_use_module 'nyc' '14.1.1' + fi - | # Configure supertest for http calls if node_version_lt '0.10'; then npm_use_module 'supertest' '1.1.0' @@ -90,9 +93,9 @@ before_install: npm rebuild fi script: - # Run test script, depending on istanbul install + # Run test script, depending on nyc install - | - if npm_module_installed 'istanbul'; then npm run-script test-travis + if npm_module_installed 'nyc'; then npm run-script test-ci else npm test fi # Run linting, depending on eslint install @@ -102,7 +105,7 @@ script: after_script: # Upload coverage to coveralls if exists - | - if [[ -f ./coverage/lcov.info ]]; then + if [[ -d .nyc_output ]]; then npm install --save-dev coveralls@2 - coveralls < ./coverage/lcov.info + nyc report --reporter=text-lcov | coveralls fi diff --git a/package.json b/package.json index d80bfc6..583c472 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "eslint": "7.26.0", "eslint-plugin-markdown": "2.1.0", "finalhandler": "1.1.2", - "istanbul": "0.4.5", "mocha": "8.4.0", + "nyc": "15.1.0", "safe-buffer": "5.2.1", "supertest": "6.1.3" }, @@ -40,8 +40,8 @@ "scripts": { "lint": "eslint .", "test": "mocha --reporter spec --bail --check-leaks test/", - "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", - "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/", + "test-ci": "nyc --reporter=html --reporter=text npm test", + "test-cov": "nyc --reporter=text npm test", "version": "node scripts/version-history.js && git add HISTORY.md" } } From 8643ec6a63a09ffaeb492b1513cc63fc8ac93950 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 17 May 2021 11:55:46 -0400 Subject: [PATCH 101/207] build: use GitHub Actions instead of Travis CI --- .github/workflows/ci.yml | 180 +++++++++++++++++++++++++++++++++++++++ .travis.yml | 111 ------------------------ README.md | 6 +- package.json | 2 +- 4 files changed, 184 insertions(+), 115 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b52cfc9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,180 @@ +name: ci + +on: +- pull_request +- push + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + name: + - Node.js 0.8 + - Node.js 0.10 + - Node.js 0.12 + - io.js 1.x + - io.js 2.x + - io.js 3.x + - Node.js 4.x + - Node.js 5.x + - Node.js 6.x + - Node.js 7.x + - Node.js 8.x + - Node.js 9.x + - Node.js 10.x + - Node.js 11.x + - Node.js 12.x + - Node.js 13.x + - Node.js 14.x + - Node.js 15.x + - Node.js 16.x + + include: + - name: Node.js 0.8 + node-version: "0.8" + npm-i: mocha@2.5.3 supertest@1.1.0 + npm-rm: nyc + + - name: Node.js 0.10 + node-version: "0.10" + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + + - name: Node.js 0.12 + node-version: "0.12" + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + + - name: io.js 1.x + node-version: "1.8" + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + + - name: io.js 2.x + node-version: "2.5" + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + + - name: io.js 3.x + node-version: "3.3" + npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 + + - name: Node.js 4.x + node-version: "4.9" + npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 + + - name: Node.js 5.x + node-version: "5.12" + npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 + + - name: Node.js 6.x + node-version: "6.17" + npm-i: mocha@6.2.2 nyc@14.1.1 + + - name: Node.js 7.x + node-version: "7.10" + npm-i: mocha@6.2.2 nyc@14.1.1 + + - name: Node.js 8.x + node-version: "8.17" + npm-i: mocha@7.2.0 + + - name: Node.js 9.x + node-version: "9.11" + npm-i: mocha@7.2.0 + + - name: Node.js 10.x + node-version: "10.24" + + - name: Node.js 11.x + node-version: "11.15" + + - name: Node.js 12.x + node-version: "12.22" + + - name: Node.js 13.x + node-version: "13.14" + + - name: Node.js 14.x + node-version: "14.17" + + - name: Node.js 15.x + node-version: "15.14" + + - name: Node.js 16.x + node-version: "16.1" + + steps: + - uses: actions/checkout@v2 + + - name: Install Node.js ${{ matrix.node-version }} + shell: bash -eo pipefail -l {0} + run: | + nvm install --default ${{ matrix.node-version }} + if [[ "${{ matrix.node-version }}" == 0.* ]]; then + npm config set strict-ssl false + fi + dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH" + + - name: Configure npm + run: npm config set shrinkwrap false + + - name: Remove npm module(s) ${{ matrix.npm-rm }} + run: npm rm --silent --save-dev ${{ matrix.npm-rm }} + if: matrix.npm-rm != '' + + - name: Install npm module(s) ${{ matrix.npm-i }} + run: npm install --save-dev ${{ matrix.npm-i }} + if: matrix.npm-i != '' + + - name: Setup Node.js version-specific dependencies + shell: bash + run: | + # eslint for linting + # - remove on Node.js < 10 + if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then + node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ + grep -E '^eslint(-|$)' | \ + sort -r | \ + xargs -n1 npm rm --silent --save-dev + fi + + - name: Install Node.js dependencies + run: npm install + + - name: List environment + id: list_env + shell: bash + run: | + echo "node@$(node -v)" + echo "npm@$(npm -v)" + npm -s ls ||: + (npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print "::set-output name=" $2 "::" $3 }' + + - name: Run tests + shell: bash + run: | + if npm -ps ls nyc | grep -q nyc; then + npm run test-ci + else + npm test + fi + + - name: Lint code + if: steps.list_env.outputs.eslint != '' + run: npm run lint + + - name: Collect code coverage + uses: coverallsapp/github-action@master + if: steps.list_env.outputs.nyc != '' + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + flag-name: run-${{ matrix.test_number }} + parallel: true + + coverage: + needs: test + runs-on: ubuntu-latest + steps: + - name: Upload code coverage + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + parallel-finished: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a771aa4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,111 +0,0 @@ -language: node_js -node_js: - - "0.8" - - "0.10" - - "0.12" - - "1.8" - - "2.5" - - "3.3" - - "4.9" - - "5.12" - - "6.17" - - "7.10" - - "8.17" - - "9.11" - - "10.24" - - "11.15" - - "12.22" - - "13.14" - - "14.17" - - "15.14" - - "16.1" -cache: - directories: - - node_modules -before_install: - - | - # Setup utility functions - function node_version_lt () { - [[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v "${1}")" ]] - } - function npm_module_installed () { - npm -lsp ls | grep -Fq "$(pwd)/node_modules/${1}:${1}@" - } - function npm_remove_module_re () { - node -e ' - fs = require("fs"); - p = JSON.parse(fs.readFileSync("package.json", "utf8")); - r = RegExp(process.argv[1]); - for (k in p.devDependencies) { - if (r.test(k)) delete p.devDependencies[k]; - } - fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n"); - ' "$@" - } - function npm_use_module () { - node -e ' - fs = require("fs"); - p = JSON.parse(fs.readFileSync("package.json", "utf8")); - p.devDependencies[process.argv[1]] = process.argv[2]; - fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n"); - ' "$@" - } - function v () { - tr '.' '\n' <<< "${1}" \ - | awk '{ printf "%03d", $0 }' \ - | sed 's/^0*//' - } - # Configure npm - - | - # Skip updating shrinkwrap / lock - npm config set shrinkwrap false - # Setup Node.js version-specific dependencies - - | - # Configure eslint for linting - if node_version_lt '10.0'; then npm_remove_module_re '^eslint(-|$)' - fi - - | - # Configure mocha for testing - if node_version_lt '0.10'; then npm_use_module 'mocha' '2.5.3' - elif node_version_lt '4.0' ; then npm_use_module 'mocha' '3.5.3' - elif node_version_lt '6.0' ; then npm_use_module 'mocha' '5.2.0' - elif node_version_lt '8.0' ; then npm_use_module 'mocha' '6.2.2' - elif node_version_lt '10.0'; then npm_use_module 'mocha' '7.2.0' - fi - - | - # Configure nyc for coverage - if node_version_lt '0.10'; then npm_remove_module_re '^nyc$' - elif node_version_lt '4.0' ; then npm_use_module 'nyc' '10.3.2' - elif node_version_lt '6.0' ; then npm_use_module 'nyc' '11.9.0' - elif node_version_lt '8.0' ; then npm_use_module 'nyc' '14.1.1' - fi - - | - # Configure supertest for http calls - if node_version_lt '0.10'; then npm_use_module 'supertest' '1.1.0' - elif node_version_lt '4.0' ; then npm_use_module 'supertest' '2.0.0' - elif node_version_lt '6.0' ; then npm_use_module 'supertest' '3.4.2' - fi - # Update Node.js modules - - | - # Prune and rebuild node_modules - if [[ -d node_modules ]]; then - npm prune - npm rebuild - fi -script: - # Run test script, depending on nyc install - - | - if npm_module_installed 'nyc'; then npm run-script test-ci - else npm test - fi - # Run linting, depending on eslint install - - | - if npm_module_installed 'eslint'; then npm run-script lint - fi -after_script: - # Upload coverage to coveralls if exists - - | - if [[ -d .nyc_output ]]; then - npm install --save-dev coveralls@2 - nyc report --reporter=text-lcov | coveralls - fi diff --git a/README.md b/README.md index 591fd60..fe4e570 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![Node.js Version][node-version-image]][node-version-url] -[![Build Status][travis-image]][travis-url] +[![Build Status][ci-image]][ci-url] [![Test Coverage][coveralls-image]][coveralls-url] Simple middleware-style router @@ -381,12 +381,12 @@ server.listen(8080) [MIT](LICENSE) +[ci-image]: https://badgen.net/github/checks/pillarjs/router/master?label=ci +[ci-url]: https://github.com/pillarjs/router/actions?query=workflow%3Aci [npm-image]: https://img.shields.io/npm/v/router.svg [npm-url]: https://npmjs.org/package/router [node-version-image]: https://img.shields.io/node/v/router.svg [node-version-url]: http://nodejs.org/download/ -[travis-image]: https://img.shields.io/travis/pillarjs/router/master.svg -[travis-url]: https://travis-ci.org/pillarjs/router [coveralls-image]: https://img.shields.io/coveralls/pillarjs/router/master.svg [coveralls-url]: https://coveralls.io/r/pillarjs/router?branch=master [downloads-image]: https://img.shields.io/npm/dm/router.svg diff --git a/package.json b/package.json index 583c472..2495c71 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "scripts": { "lint": "eslint .", "test": "mocha --reporter spec --bail --check-leaks test/", - "test-ci": "nyc --reporter=html --reporter=text npm test", + "test-ci": "nyc --reporter=lcov --reporter=text npm test", "test-cov": "nyc --reporter=text npm test", "version": "node scripts/version-history.js && git add HISTORY.md" } From e96ebf5ab30661905107e1ff15250baeb4a47b9f Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 17 May 2021 12:36:53 -0400 Subject: [PATCH 102/207] Fix handling very large stacks of sync middleware --- HISTORY.md | 1 + index.js | 8 ++++++++ lib/route.js | 14 ++++++++++++++ test/route.js | 18 ++++++++++++++++++ test/router.js | 17 +++++++++++++++++ 5 files changed, 58 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 322ef5e..6a8d71c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,7 @@ unreleased ========== + * Fix handling very large stacks of sync middleware * deps: safe-buffer@5.2.1 1.3.5 / 2020-03-24 diff --git a/index.js b/index.js index 3608f26..4220442 100644 --- a/index.js +++ b/index.js @@ -163,6 +163,7 @@ Router.prototype.handle = function handle(req, res, callback) { var removed = '' var self = this var slashAdded = false + var sync = 0 var paramcalled = {} // middleware and routes @@ -218,6 +219,11 @@ Router.prototype.handle = function handle(req, res, callback) { return } + // max sync stack + if (++sync > 100) { + return defer(next, err) + } + // get pathname of request var path = getPathname(req) @@ -340,6 +346,8 @@ Router.prototype.handle = function handle(req, res, callback) { } else { layer.handle_request(req, res, next) } + + sync = 0 } } diff --git a/lib/route.js b/lib/route.js index 98363fe..a6a55a5 100644 --- a/lib/route.js +++ b/lib/route.js @@ -24,6 +24,11 @@ var methods = require('methods') var slice = Array.prototype.slice +/* istanbul ignore next */ +var defer = typeof setImmediate === 'function' + ? setImmediate + : function (fn) { process.nextTick(fn.bind.apply(fn, arguments)) } + /** * Expose `Route`. */ @@ -95,6 +100,8 @@ Route.prototype._methods = function _methods() { Route.prototype.dispatch = function dispatch(req, res, done) { var idx = 0 var stack = this.stack + var sync = 0 + if (stack.length === 0) { return done() } @@ -124,6 +131,11 @@ Route.prototype.dispatch = function dispatch(req, res, done) { return done(err) } + // max sync stack + if (++sync > 100) { + return defer(next, err) + } + var layer var match @@ -143,6 +155,8 @@ Route.prototype.dispatch = function dispatch(req, res, done) { } else { layer.handle_request(req, res, next) } + + sync = 0 } } diff --git a/test/route.js b/test/route.js index a88b29f..ba00fec 100644 --- a/test/route.js +++ b/test/route.js @@ -103,6 +103,24 @@ describe('Router', function () { .expect(404, done) }) + it('should not stack overflow with a large sync stack', function (done) { + this.timeout(5000) // long-running test + + var router = new Router() + var route = router.route('/foo') + var server = createServer(router) + + for (var i = 0; i < 6000; i++) { + route.all(function (req, res, next) { next() }) + } + + route.get(helloWorld) + + request(server) + .get('/foo') + .expect(200, 'hello, world', done) + }) + describe('.all(...fn)', function () { it('should reject no arguments', function () { var router = new Router() diff --git a/test/router.js b/test/router.js index 138f221..9d011ed 100644 --- a/test/router.js +++ b/test/router.js @@ -577,6 +577,23 @@ describe('Router', function () { .expect(404, done) }) + it('should not stack overflow with a large sync stack', function (done) { + this.timeout(5000) // long-running test + + var router = new Router() + var server = createServer(router) + + for (var i = 0; i < 6000; i++) { + router.use(function (req, res, next) { next() }) + } + + router.use(helloWorld) + + request(server) + .get('/') + .expect(200, 'hello, world', done) + }) + describe('error handling', function () { it('should invoke error function after next(err)', function (done) { var router = new Router() From d115b11b2238dc078e05b15080cbfee96d81d885 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 3 Oct 2021 21:44:00 -0400 Subject: [PATCH 103/207] build: update CI for npm TLS upgrade --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b52cfc9..524e778 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,7 +108,10 @@ jobs: shell: bash -eo pipefail -l {0} run: | nvm install --default ${{ matrix.node-version }} - if [[ "${{ matrix.node-version }}" == 0.* ]]; then + if [[ "${{ matrix.node-version }}" == 0.* && "$(cut -d. -f2 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then + nvm install --alias=npm 0.10 + nvm use ${{ matrix.node-version }} + sed -i '1s;^.*$;'"$(printf '#!%q' "$(nvm which npm)")"';' "$(readlink -f "$(which npm)")" npm config set strict-ssl false fi dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH" From 4b2703110340cf3ea00b7c3d35f3aa9c2ca0c713 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 3 Oct 2021 21:46:00 -0400 Subject: [PATCH 104/207] build: Node.js@14.18 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 524e778..6c2131c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,7 +93,7 @@ jobs: node-version: "13.14" - name: Node.js 14.x - node-version: "14.17" + node-version: "14.18" - name: Node.js 15.x node-version: "15.14" From 6b0756d3c22e122099d915038f06ef8d5266d5e0 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 3 Oct 2021 21:50:00 -0400 Subject: [PATCH 105/207] build: eslint@7.32.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2495c71..a76936d 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "7.26.0", + "eslint": "7.32.0", "eslint-plugin-markdown": "2.1.0", "finalhandler": "1.1.2", "mocha": "8.4.0", From 5ed19f49cdd067f3c089eaebe2d3e804476e7f1b Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sun, 3 Oct 2021 21:55:00 -0400 Subject: [PATCH 106/207] build: eslint-plugin-markdown@2.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a76936d..7ab0d0a 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "devDependencies": { "after": "0.8.2", "eslint": "7.32.0", - "eslint-plugin-markdown": "2.1.0", + "eslint-plugin-markdown": "2.2.1", "finalhandler": "1.1.2", "mocha": "8.4.0", "nyc": "15.1.0", From d45d0fa367d8d0bccb9a734048a4c629df7b1622 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 15 Nov 2021 17:36:21 -0500 Subject: [PATCH 107/207] build: supertest@6.1.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7ab0d0a..d7c9707 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "mocha": "8.4.0", "nyc": "15.1.0", "safe-buffer": "5.2.1", - "supertest": "6.1.3" + "supertest": "6.1.6" }, "files": [ "lib/", From 0d4633703537f069cad2fd9e447395542f565023 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 15 Nov 2021 17:37:17 -0500 Subject: [PATCH 108/207] build: mocha@9.1.3 --- .github/workflows/ci.yml | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c2131c..744aa95 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,9 +82,11 @@ jobs: - name: Node.js 10.x node-version: "10.24" + npm-i: mocha@8.4.0 - name: Node.js 11.x node-version: "11.15" + npm-i: mocha@8.4.0 - name: Node.js 12.x node-version: "12.22" diff --git a/package.json b/package.json index d7c9707..4c89d80 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "eslint": "7.32.0", "eslint-plugin-markdown": "2.2.1", "finalhandler": "1.1.2", - "mocha": "8.4.0", + "mocha": "9.1.3", "nyc": "15.1.0", "safe-buffer": "5.2.1", "supertest": "6.1.6" From 78d067f4c4fd124d241e9161883081240cd9c6ef Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 15 Nov 2021 17:40:04 -0500 Subject: [PATCH 109/207] build: Node.js@16.13 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 744aa95..9414d16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -101,7 +101,7 @@ jobs: node-version: "15.14" - name: Node.js 16.x - node-version: "16.1" + node-version: "16.13" steps: - uses: actions/checkout@v2 From c030e5310fc5f5da85950ff51392c2ae4626f283 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 15 Nov 2021 17:40:31 -0500 Subject: [PATCH 110/207] build: support Node.js 17.x --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9414d16..85a2d8c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,7 @@ jobs: - Node.js 14.x - Node.js 15.x - Node.js 16.x + - Node.js 17.x include: - name: Node.js 0.8 @@ -103,6 +104,9 @@ jobs: - name: Node.js 16.x node-version: "16.13" + - name: Node.js 17.x + node-version: "17.1" + steps: - uses: actions/checkout@v2 From 0298aa8a6e451e569559833ab734a4fc4bdd12cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Fantone?= Date: Mon, 15 Nov 2021 23:34:13 +0000 Subject: [PATCH 111/207] tests: fix typos in test descriptions --- test/req.params.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/req.params.js b/test/req.params.js index 46e5b19..fc0e16c 100644 --- a/test/req.params.js +++ b/test/req.params.js @@ -68,7 +68,7 @@ describe('req.params', function () { }) describe('when "mergeParams: true"', function () { - it('should merge outsite object with params', function (done) { + it('should merge outside object with params', function (done) { var router = Router({ mergeParams: true }) var server = createServer(function (req, res, next) { req.params = {'foo': 'bar'} @@ -87,7 +87,7 @@ describe('req.params', function () { .expect(200, '{"foo":"bar"}', done) }) - it('should ignore non-object outsite object', function (done) { + it('should ignore non-object outside object', function (done) { var router = Router({ mergeParams: true }) var server = createServer(function (req, res, next) { req.params = 42 @@ -126,7 +126,7 @@ describe('req.params', function () { }) describe('with numeric properties in req.params', function () { - it('should merge numeric properies by offsetting', function (done) { + it('should merge numeric properties by offsetting', function (done) { var router = Router({ mergeParams: true }) var server = createServer(function (req, res, next) { req.params = {'0': 'foo', '1': 'bar'} From 3b8351859859c259aa0c8b1174693b82aab04d35 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 15 Nov 2021 19:08:32 -0500 Subject: [PATCH 112/207] 1.3.6 --- HISTORY.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 6a8d71c..81325b6 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,5 @@ -unreleased -========== +1.3.6 / 2021-11-15 +================== * Fix handling very large stacks of sync middleware * deps: safe-buffer@5.2.1 diff --git a/package.json b/package.json index 4c89d80..29c5e47 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "router", "description": "Simple middleware-style router", - "version": "1.3.5", + "version": "1.3.6", "author": "Douglas Christopher Wilson ", "contributors": [ "Blake Embrey " From 46d05d7f741912bd7ff6fba6a11aa047387a604d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Fantone?= Date: Mon, 15 Nov 2021 23:34:13 +0000 Subject: [PATCH 113/207] docs: fix typo in history --- HISTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 438dfaa..a85082d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -18,7 +18,7 @@ This incorporates all changes after 1.3.3 up to 1.3.5. `(*)` is no longer valid and must be written as `(.*)`, for example. - Named matching groups no longer available by position in `req.params`. `/:foo(.*)` only captures as `req.params.foo` and not available as - `req.parmas[0]`. + `req.params[0]`. - Regular expressions can only be used in a matching group. `/\\d+` is no longer valid and must be written as `/(\\d+)`. - Special `*` path segment behavior removed. From 83dc50436b78415600b98d6c22c2cbebadd27664 Mon Sep 17 00:00:00 2001 From: Jon Church Date: Sat, 18 Apr 2020 21:13:47 -0400 Subject: [PATCH 114/207] Add support for returned, rejected Promises to router.param closes #91 closes #92 --- HISTORY.md | 2 ++ README.md | 5 +++++ index.js | 8 +++++++- lib/layer.js | 15 +-------------- package.json | 1 + test/param.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 15 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index a85082d..78c4ee4 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,8 @@ This incorporates all changes after 1.3.5 up to 1.3.6. + * Add support for returned, rejected Promises to `router.param` + 2.0.0-beta.1 / 2020-03-29 ========================= diff --git a/README.md b/README.md index b105931..77cbddc 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,11 @@ Maps the specified path parameter `name` to a specialized param-capturing middle This function positions the middleware in the same stack as `.use`. +The function can optionally return a `Promise` object. If a `Promise` object +is returned from the function, the router will attach an `onRejected` callback +using `.then`. If the promise is rejected, `next` will be called with the +rejected value, or an error if the value is falsy. + Parameter mapping is used to provide pre-conditions to routes which use normalized placeholders. For example a _:user_id_ parameter could automatically load a user's information from the database without diff --git a/index.js b/index.js index 6dbb540..c9ee0fa 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,7 @@ */ var flatten = require('array-flatten').flatten +var isPromise = require('is-promise') var Layer = require('./lib/layer') var methods = require('methods') var mixin = require('utils-merge') @@ -642,7 +643,12 @@ function processParams (params, layer, called, req, res, done) { if (!fn) return param() try { - fn(req, res, paramCallback, paramVal, key.name) + var ret = fn(req, res, paramCallback, paramVal, key.name) + if (isPromise(ret)) { + ret.then(null, function (error) { + paramCallback(error || new Error('Rejected promise')) + }) + } } catch (e) { paramCallback(e) } diff --git a/lib/layer.js b/lib/layer.js index 39acfe2..4936ca2 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -12,6 +12,7 @@ * @private */ +var isPromise = require('is-promise') var pathRegexp = require('path-to-regexp') /** @@ -187,20 +188,6 @@ function decodeParam (val) { } } -/** - * Returns true if the val is a Promise. - * - * @param {*} val - * @return {boolean} - * @private - */ - -function isPromise (val) { - return val && - typeof val === 'object' && - typeof val.then === 'function' -} - /** * Loosens the given path for path-to-regexp matching. */ diff --git a/package.json b/package.json index fa25e86..e85a87a 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "repository": "pillarjs/router", "dependencies": { "array-flatten": "3.0.0", + "is-promise": "4.0.0", "methods": "~1.1.2", "parseurl": "~1.3.3", "path-to-regexp": "3.2.0", diff --git a/test/param.js b/test/param.js index 43245fc..e2ca379 100644 --- a/test/param.js +++ b/test/param.js @@ -10,6 +10,8 @@ var shouldNotHitHandle = utils.shouldNotHitHandle var createServer = utils.createServer var request = utils.request +var describePromises = global.Promise ? describe : describe.skip + describe('Router', function () { describe('.param(name, fn)', function () { it('should reject missing name', function () { @@ -254,6 +256,48 @@ describe('Router', function () { .expect(500, /Error: boom/, done) }) + describePromises('promise support', function () { + it('should pass rejected promise value', function (done) { + var router = new Router() + var server = createServer(router) + + router.param('user', function parseUser (req, res, next, user) { + return Promise.reject(new Error('boom')) + }) + + router.get('/user/:user', function (req, res) { + res.setHeader('Content-Type', 'text/plain') + res.end('get user ' + req.params.id) + }) + + request(server) + .get('/user/bob') + .expect(500, /Error: boom/, done) + }) + + it('should pass rejected promise without value', function (done) { + var router = new Router() + var server = createServer(router) + + router.use(function createError (req, res, next) { + return Promise.reject() // eslint-disable-line prefer-promise-reject-errors + }) + + router.param('user', function parseUser (req, res, next, user) { + return Promise.reject() // eslint-disable-line prefer-promise-reject-errors + }) + + router.get('/user/:user', function (req, res) { + res.setHeader('Content-Type', 'text/plain') + res.end('get user ' + req.params.id) + }) + + request(server) + .get('/user/bob') + .expect(500, /Error: Rejected promise/, done) + }) + }) + describe('next("route")', function () { it('should cause route with param to be skipped', function (done) { var cb = after(3, done) From 7506e77b74caf77d4a19026ccdad7e341e40a406 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 15 Mar 2022 20:33:13 -0400 Subject: [PATCH 115/207] build: use supertest@3.4.2 for Node.js 6.x --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85a2d8c..4136f55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,7 +67,7 @@ jobs: - name: Node.js 6.x node-version: "6.17" - npm-i: mocha@6.2.2 nyc@14.1.1 + npm-i: mocha@6.2.2 nyc@14.1.1 supertest@3.4.2 - name: Node.js 7.x node-version: "7.10" From 198085578f681c5085bea59a1124513ee41d4928 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 15 Mar 2022 20:35:52 -0400 Subject: [PATCH 116/207] build: mocha@9.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 29c5e47..e3abeca 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "eslint": "7.32.0", "eslint-plugin-markdown": "2.2.1", "finalhandler": "1.1.2", - "mocha": "9.1.3", + "mocha": "9.2.2", "nyc": "15.1.0", "safe-buffer": "5.2.1", "supertest": "6.1.6" From dfec35b51a166f6f183b46a0fbbd101950ee349e Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 25 Mar 2022 21:09:35 -0400 Subject: [PATCH 117/207] build: finalhandler@1.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e3abeca..d2dafd3 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "after": "0.8.2", "eslint": "7.32.0", "eslint-plugin-markdown": "2.2.1", - "finalhandler": "1.1.2", + "finalhandler": "1.2.0", "mocha": "9.2.2", "nyc": "15.1.0", "safe-buffer": "5.2.1", From 10c3dcab83593019e35e7a568b55d1d4c53cbcff Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 25 Mar 2022 21:11:38 -0400 Subject: [PATCH 118/207] build: Node.js@17.8 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4136f55..e5af75a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,7 +105,7 @@ jobs: node-version: "16.13" - name: Node.js 17.x - node-version: "17.1" + node-version: "17.8" steps: - uses: actions/checkout@v2 From da54d5a83d066e5f2b6d0734f49e84049ee4c4ae Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 26 Mar 2022 00:18:30 -0400 Subject: [PATCH 119/207] build: Node.js@16.14 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5af75a..30cad1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,7 +102,7 @@ jobs: node-version: "15.14" - name: Node.js 16.x - node-version: "16.13" + node-version: "16.14" - name: Node.js 17.x node-version: "17.8" From 09c5311f0b5b70472b657808405754ff64e1a2e6 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 26 Mar 2022 00:20:51 -0400 Subject: [PATCH 120/207] build: Node.js@14.19 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 30cad1c..3653378 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,7 +96,7 @@ jobs: node-version: "13.14" - name: Node.js 14.x - node-version: "14.18" + node-version: "14.19" - name: Node.js 15.x node-version: "15.14" From 54f777758aef947297a97fc9576c5f33ebd40a16 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 19 Apr 2022 20:04:50 -0400 Subject: [PATCH 121/207] build: Node.js@17.9 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3653378..78d4747 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,7 +105,7 @@ jobs: node-version: "16.14" - name: Node.js 17.x - node-version: "17.8" + node-version: "17.9" steps: - uses: actions/checkout@v2 From 8773cfd3ee93f3b0b8563ce3c46f4971a47ea207 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 19 Apr 2022 20:09:31 -0400 Subject: [PATCH 122/207] build: support Node.js 18.x --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78d4747..5ddff18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,7 @@ jobs: - Node.js 15.x - Node.js 16.x - Node.js 17.x + - Node.js 18.x include: - name: Node.js 0.8 @@ -107,6 +108,9 @@ jobs: - name: Node.js 17.x node-version: "17.9" + - name: Node.js 18.x + node-version: "18.0" + steps: - uses: actions/checkout@v2 From ba62d17dfe1b7c58d64a042bc6a8ebf4eb6bf1d2 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 20 Apr 2022 00:18:39 -0400 Subject: [PATCH 123/207] lint: remove deprecated String.prototype.substr --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 4220442..6fd13cf 100644 --- a/index.js +++ b/index.js @@ -196,14 +196,14 @@ Router.prototype.handle = function handle(req, res, callback) { // remove added slash if (slashAdded) { - req.url = req.url.substr(1) + req.url = req.url.slice(1) slashAdded = false } // restore altered req.url if (removed.length !== 0) { req.baseUrl = parentUrl - req.url = protohost + removed + req.url.substr(protohost.length) + req.url = protohost + removed + req.url.slice(protohost.length) removed = '' } @@ -309,7 +309,7 @@ Router.prototype.handle = function handle(req, res, callback) { function trim_prefix(layer, layerError, layerPath, path) { if (layerPath.length !== 0) { // Validate path is a prefix match - if (layerPath !== path.substr(0, layerPath.length)) { + if (layerPath !== path.substring(0, layerPath.length)) { next(layerError) return } @@ -325,7 +325,7 @@ Router.prototype.handle = function handle(req, res, callback) { // middleware (.use stuff) needs to have the path stripped debug('trim prefix (%s) from url %s', layerPath, req.url) removed = layerPath - req.url = protohost + req.url.substr(protohost.length + removed.length) + req.url = protohost + req.url.slice(protohost.length + removed.length) // Ensure leading slash if (!protohost && req.url[0] !== '/') { @@ -598,10 +598,10 @@ function getProtohost(url) { var pathLength = searchIndex !== -1 ? searchIndex : url.length - var fqdnIndex = url.substr(0, pathLength).indexOf('://') + var fqdnIndex = url.substring(0, pathLength).indexOf('://') return fqdnIndex !== -1 - ? url.substr(0, url.indexOf('/', 3 + fqdnIndex)) + ? url.substring(0, url.indexOf('/', 3 + fqdnIndex)) : undefined } From 5e46aa32917b52b94178782cd060b065060aae16 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 28 Apr 2022 00:06:57 -0400 Subject: [PATCH 124/207] Fix hanging on large stack of sync routes --- HISTORY.md | 5 +++++ index.js | 14 ++++++-------- test/router.js | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 81325b6..6b4f32d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * Fix hanging on large stack of sync routes + 1.3.6 / 2021-11-15 ================== diff --git a/index.js b/index.js index 6fd13cf..172a2ef 100644 --- a/index.js +++ b/index.js @@ -295,14 +295,14 @@ Router.prototype.handle = function handle(req, res, callback) { // this should be done for the layer self.process_params(layer, paramcalled, req, res, function (err) { if (err) { - return next(layerError || err) + next(layerError || err) + } else if (route) { + layer.handle_request(req, res, next) + } else { + trim_prefix(layer, layerError, layerPath, path) } - if (route) { - return layer.handle_request(req, res, next) - } - - trim_prefix(layer, layerError, layerPath, path) + sync = 0 }) } @@ -346,8 +346,6 @@ Router.prototype.handle = function handle(req, res, callback) { } else { layer.handle_request(req, res, next) } - - sync = 0 } } diff --git a/test/router.js b/test/router.js index 9d011ed..ba978f2 100644 --- a/test/router.js +++ b/test/router.js @@ -146,6 +146,23 @@ describe('Router', function () { .expect(200, 'hello, world', done) }) + it('should not stack overflow with a large sync stack', function (done) { + this.timeout(5000) // long-running test + + var router = new Router() + var server = createServer(router) + + for (var i = 0; i < 6000; i++) { + router.get('/foo', function (req, res, next) { next() }) + } + + router.get('/foo', helloWorld) + + request(server) + .get('/foo') + .expect(200, 'hello, world', done) + }) + describe('with "caseSensitive" option', function () { it('should not match paths case-sensitively by default', function (done) { var cb = after(3, done) From 2635990e7186f43b661787d4fc8039bfb0a07a16 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 28 Apr 2022 00:09:55 -0400 Subject: [PATCH 125/207] build: supertest@6.2.3 --- .github/workflows/ci.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ddff18..e4c0ab0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: - name: Node.js 7.x node-version: "7.10" - npm-i: mocha@6.2.2 nyc@14.1.1 + npm-i: mocha@6.2.2 nyc@14.1.1 supertest@6.1.6 - name: Node.js 8.x node-version: "8.17" diff --git a/package.json b/package.json index d2dafd3..2bd98b7 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "mocha": "9.2.2", "nyc": "15.1.0", "safe-buffer": "5.2.1", - "supertest": "6.1.6" + "supertest": "6.2.3" }, "files": [ "lib/", From 75378cd6884c3ed984c8ec1dc7a8b0bcbbb51515 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 28 Apr 2022 10:27:19 -0400 Subject: [PATCH 126/207] build: fix code coverage aggregate upload --- .github/workflows/ci.yml | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4c0ab0..a767a54 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -166,6 +166,7 @@ jobs: run: | if npm -ps ls nyc | grep -q nyc; then npm run test-ci + cp coverage/lcov.info "coverage/${{ matrix.name }}.lcov" else npm test fi @@ -175,19 +176,43 @@ jobs: run: npm run lint - name: Collect code coverage - uses: coverallsapp/github-action@master + if: steps.list_env.outputs.nyc != '' + run: | + if [[ -d ./coverage ]]; then + mv ./coverage "./${{ matrix.name }}" + mkdir ./coverage + mv "./${{ matrix.name }}" "./coverage/${{ matrix.name }}" + fi + - name: Upload code coverage + uses: actions/upload-artifact@v2 + if: steps.list_env.outputs.nyc != '' with: - github-token: ${{ secrets.GITHUB_TOKEN }} - flag-name: run-${{ matrix.test_number }} - parallel: true + name: coverage + path: ./coverage + retention-days: 1 coverage: needs: test runs-on: ubuntu-latest steps: - - name: Upload code coverage + - uses: actions/checkout@v2 + + - name: Install lcov + shell: bash + run: sudo apt-get -y install lcov + + - name: Collect coverage reports + uses: actions/download-artifact@v2 + with: + name: coverage + path: ./coverage + + - name: Merge coverage reports + shell: bash + run: find ./coverage -name lcov.info -exec printf '-a %q\n' {} \; | xargs lcov -o ./coverage/lcov.info + + - name: Upload coverage report uses: coverallsapp/github-action@master with: - github-token: ${{ secrets.github_token }} - parallel-finished: true + github-token: ${{ secrets.GITHUB_TOKEN }} From 2d8f8fb5df0ae75bf6ffac4b25ddb538bcec28fa Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 28 Apr 2022 10:32:03 -0400 Subject: [PATCH 127/207] build: Node.js@16.15 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a767a54..f9bfe2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,7 +103,7 @@ jobs: node-version: "15.14" - name: Node.js 16.x - node-version: "16.14" + node-version: "16.15" - name: Node.js 17.x node-version: "17.9" From f89db79a2844e96ab9f2871ab178356ce502b206 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 28 Apr 2022 11:11:19 -0400 Subject: [PATCH 128/207] docs: add security policy --- SECURITY.md | 24 ++++++++++++++++++++++++ package.json | 1 + 2 files changed, 25 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..d56acec --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,24 @@ +# Security Policies and Procedures + +## Reporting a Bug + +The `router` team and community take all security bugs seriously. Thank you +for improving the security of the project. We appreciate your efforts and +responsible disclosure and will make every effort to acknowledge your +contributions. + +Report security bugs by emailing the current owner(s) of `router`. This information +can be found in the npm registry using the command `npm owner ls router`. +If unsure or unable to get the information from the above, open an issue +in the [project issue tracker](https://github.com/pillarjs/router/issues) +asking for the current contact information. + +To ensure the timely response to your report, please ensure that the entirety +of the report is contained within the email body and not solely behind a web +link or an attachment. + +At least one owner will acknowledge your email within 48 hours, and will send a +more detailed response within 48 hours indicating the next steps in handling +your report. After the initial reply to your report, the owners will +endeavor to keep you informed of the progress towards a fix and full +announcement, and may ask for additional information or guidance. diff --git a/package.json b/package.json index 2bd98b7..b850e45 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "LICENSE", "HISTORY.md", "README.md", + "SECURITY.md", "index.js" ], "engines": { From 6bafbd3cb7554f334ae060e629798d5e7360e5bd Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 28 Apr 2022 11:17:14 -0400 Subject: [PATCH 129/207] docs: update CI badge link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fe4e570..48e5857 100644 --- a/README.md +++ b/README.md @@ -382,7 +382,7 @@ server.listen(8080) [MIT](LICENSE) [ci-image]: https://badgen.net/github/checks/pillarjs/router/master?label=ci -[ci-url]: https://github.com/pillarjs/router/actions?query=workflow%3Aci +[ci-url]: https://github.com/pillarjs/router/actions/workflows/ci.yml [npm-image]: https://img.shields.io/npm/v/router.svg [npm-url]: https://npmjs.org/package/router [node-version-image]: https://img.shields.io/node/v/router.svg From cbaba0fb106d98a25dd341a512a2dd0004a2c80d Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 28 Apr 2022 11:31:51 -0400 Subject: [PATCH 130/207] docs: update copyright --- LICENSE | 2 +- index.js | 2 +- lib/layer.js | 2 +- lib/route.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index 31e7f7d..237e1b6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ (The MIT License) Copyright (c) 2013 Roman Shtylman -Copyright (c) 2014 Douglas Christopher Wilson +Copyright (c) 2014-2022 Douglas Christopher Wilson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/index.js b/index.js index 172a2ef..362bccd 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ /*! * router * Copyright(c) 2013 Roman Shtylman - * Copyright(c) 2014 Douglas Christopher Wilson + * Copyright(c) 2014-2022 Douglas Christopher Wilson * MIT Licensed */ diff --git a/lib/layer.js b/lib/layer.js index 60a737f..430f595 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -1,7 +1,7 @@ /*! * router * Copyright(c) 2013 Roman Shtylman - * Copyright(c) 2014 Douglas Christopher Wilson + * Copyright(c) 2014-2022 Douglas Christopher Wilson * MIT Licensed */ diff --git a/lib/route.js b/lib/route.js index a6a55a5..c82a3cc 100644 --- a/lib/route.js +++ b/lib/route.js @@ -1,7 +1,7 @@ /*! * router * Copyright(c) 2013 Roman Shtylman - * Copyright(c) 2014 Douglas Christopher Wilson + * Copyright(c) 2014-2022 Douglas Christopher Wilson * MIT Licensed */ From 41f61cbe76ba4a5f4815f78db44991ea84781274 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 28 Apr 2022 12:51:02 -0400 Subject: [PATCH 131/207] 1.3.7 --- HISTORY.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 6b4f32d..9e2d8be 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,5 @@ -unreleased -========== +1.3.7 / 2022-04-28 +================== * Fix hanging on large stack of sync routes diff --git a/package.json b/package.json index b850e45..01c6742 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "router", "description": "Simple middleware-style router", - "version": "1.3.6", + "version": "1.3.7", "author": "Douglas Christopher Wilson ", "contributors": [ "Blake Embrey " From 6c5090de69f9b0cf4789dc1d9ff85b3c79f52c4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Fantone?= Date: Mon, 15 Nov 2021 23:34:13 +0000 Subject: [PATCH 132/207] docs: fix typo in history --- HISTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 0c354d8..7a451ba 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -15,7 +15,7 @@ This incorporates all changes after 1.3.3 up to 1.3.5. * deps: array-flatten@3.0.0 * deps: parseurl@~1.3.3 * deps: path-to-regexp@3.2.0 - - Add new `?`, `*`, and `+` parameter modifiers + - Add new `?`, `*`, and `+` parameter modifiers. - Matching group expressions are only RegExp syntax. `(*)` is no longer valid and must be written as `(.*)`, for example. - Named matching groups no longer available by position in `req.params`. From 2ae1045ddc7268d5022ae9355307632ad61bde9d Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 10 Jun 2022 22:23:59 -0400 Subject: [PATCH 133/207] build: eslint-plugin-import@2.26.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c885fc1..6814fae 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "after": "0.8.2", "eslint": "7.32.0", "eslint-config-standard": "14.1.1", - "eslint-plugin-import": "2.25.3", + "eslint-plugin-import": "2.26.0", "eslint-plugin-markdown": "2.2.1", "eslint-plugin-node": "11.1.0", "eslint-plugin-promise": "4.3.1", From 63ae94fec103f192e6254c5c1214d72277479a49 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 10 Jun 2022 22:29:49 -0400 Subject: [PATCH 134/207] build: eslint-plugin-promise@5.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6814fae..b18ef68 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "eslint-plugin-import": "2.26.0", "eslint-plugin-markdown": "2.2.1", "eslint-plugin-node": "11.1.0", - "eslint-plugin-promise": "4.3.1", + "eslint-plugin-promise": "5.2.0", "eslint-plugin-standard": "4.1.0", "finalhandler": "1.2.0", "mocha": "9.2.2", From efd112a386f4f26d8c2b59fe3a8abc34226ed032 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 20 Jul 2022 21:44:11 -0400 Subject: [PATCH 135/207] tests: add test for capture group regexp --- test/route.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/route.js b/test/route.js index ee3d6d7..fcdffdc 100644 --- a/test/route.js +++ b/test/route.js @@ -840,6 +840,25 @@ describe('Router', function () { .expect(200, { foo: 'fizz/buzz' }, cb) }) }) + + describe('using ":name(regexp)"', function () { + it('should limit capture group to regexp match', function (done) { + var cb = after(2, done) + var router = new Router() + var route = router.route('/:foo([0-9]+)') + var server = createServer(router) + + route.all(sendParams) + + request(server) + .get('/foo') + .expect(404, cb) + + request(server) + .get('/42') + .expect(200, { foo: '42' }, cb) + }) + }) }) }) }) From 7ddcab5c8adb8242716096e5fbb2148dd752f747 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 20 Jul 2022 21:49:54 -0400 Subject: [PATCH 136/207] tests: add test for unnamed capture group regexp --- test/route.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/route.js b/test/route.js index fcdffdc..78c3f0a 100644 --- a/test/route.js +++ b/test/route.js @@ -859,6 +859,25 @@ describe('Router', function () { .expect(200, { foo: '42' }, cb) }) }) + + describe('using "(regexp)"', function () { + it('should add capture group using regexp', function (done) { + var cb = after(2, done) + var router = new Router() + var route = router.route('/page_([0-9]+)') + var server = createServer(router) + + route.all(sendParams) + + request(server) + .get('/page_foo') + .expect(404, cb) + + request(server) + .get('/page_42') + .expect(200, { 0: '42' }, cb) + }) + }) }) }) }) From c67be541592f109e87875abf234fe49d0d83edc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Fantone?= Date: Tue, 30 Nov 2021 21:02:40 +0000 Subject: [PATCH 137/207] docs: add capture group change to history --- HISTORY.md | 2 ++ test/route.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 7a451ba..1e1e91c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -23,6 +23,8 @@ This incorporates all changes after 1.3.3 up to 1.3.5. `req.params[0]`. - Regular expressions can only be used in a matching group. `/\\d+` is no longer valid and must be written as `/(\\d+)`. + - Matching groups are now literal regular expressions. + `:foo` named captures can no longer be included inside a capture group. - Special `*` path segment behavior removed. `/foo/*/bar` will match a literal `*` as the middle segment. * deps: setprototypeof@1.2.0 diff --git a/test/route.js b/test/route.js index 78c3f0a..5bfe75b 100644 --- a/test/route.js +++ b/test/route.js @@ -877,6 +877,27 @@ describe('Router', function () { .get('/page_42') .expect(200, { 0: '42' }, cb) }) + + it('should treat regexp as literal regexp', function (done) { + var cb = after(3, done) + var router = new Router() + var route = router.route('/([a-z]+:n[0-9]+)') + var server = createServer(router) + + route.all(sendParams) + + request(server) + .get('/foo:bar') + .expect(404, cb) + + request(server) + .get('/foo:n') + .expect(404, cb) + + request(server) + .get('/foo:n42') + .expect(200, { 0: 'foo:n42' }, cb) + }) }) }) }) From 4e299a0cd1414835fa0b6ee38236453f5cd8e6e3 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 1 Aug 2022 22:41:06 -0400 Subject: [PATCH 138/207] build: Node.js@18.7 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9bfe2f..c4bb7ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,7 +109,7 @@ jobs: node-version: "17.9" - name: Node.js 18.x - node-version: "18.0" + node-version: "18.7" steps: - uses: actions/checkout@v2 From 58205b434b312e89166096d826bfcb8f2329f8d7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 1 Aug 2022 22:44:48 -0400 Subject: [PATCH 139/207] build: Node.js@16.16 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4bb7ff..173f913 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,7 +103,7 @@ jobs: node-version: "15.14" - name: Node.js 16.x - node-version: "16.15" + node-version: "16.16" - name: Node.js 17.x node-version: "17.9" From ac6a7597be4f822f42ab93b4e5974851d07f67b2 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Mon, 1 Aug 2022 22:47:42 -0400 Subject: [PATCH 140/207] build: Node.js@14.20 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 173f913..e22af91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,7 +97,7 @@ jobs: node-version: "13.14" - name: Node.js 14.x - node-version: "14.19" + node-version: "14.20" - name: Node.js 15.x node-version: "15.14" From d7a7c4d53665257af5ba1a2358620c05d6a01b71 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 3 Aug 2022 23:01:47 -0400 Subject: [PATCH 141/207] build: supertest@6.2.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 01c6742..85f4b93 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "mocha": "9.2.2", "nyc": "15.1.0", "safe-buffer": "5.2.1", - "supertest": "6.2.3" + "supertest": "6.2.4" }, "files": [ "lib/", From 03fff1ce61b5416b9b621629ca33f26ddf298149 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 23 Sep 2022 18:27:58 -0400 Subject: [PATCH 142/207] build: eslint@8.23.1 --- .github/workflows/ci.yml | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e22af91..b6e616c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -141,8 +141,8 @@ jobs: shell: bash run: | # eslint for linting - # - remove on Node.js < 10 - if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then + # - remove on Node.js < 12 + if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 12 ]]; then node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ grep -E '^eslint(-|$)' | \ sort -r | \ diff --git a/package.json b/package.json index 85f4b93..9c36dae 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "7.32.0", + "eslint": "8.23.1", "eslint-plugin-markdown": "2.2.1", "finalhandler": "1.2.0", "mocha": "9.2.2", From 9c9a2a210d7a5a1697de466ef9b4f7dd5396a099 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 23 Sep 2022 20:03:19 -0400 Subject: [PATCH 143/207] build: eslint-plugin-markdown@3.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9c36dae..62f6bf6 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "devDependencies": { "after": "0.8.2", "eslint": "8.23.1", - "eslint-plugin-markdown": "2.2.1", + "eslint-plugin-markdown": "3.0.0", "finalhandler": "1.2.0", "mocha": "9.2.2", "nyc": "15.1.0", From 2075428e130d640dffd7da9fffb14371bdcf2c6c Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 23 Sep 2022 20:10:01 -0400 Subject: [PATCH 144/207] build: mocha@10.0.0 --- .github/workflows/ci.yml | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6e616c..1afa375 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,9 +92,11 @@ jobs: - name: Node.js 12.x node-version: "12.22" + npm-i: mocha@9.2.2 - name: Node.js 13.x node-version: "13.14" + npm-i: mocha@9.2.2 - name: Node.js 14.x node-version: "14.20" diff --git a/package.json b/package.json index 62f6bf6..23a8fe7 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "eslint": "8.23.1", "eslint-plugin-markdown": "3.0.0", "finalhandler": "1.2.0", - "mocha": "9.2.2", + "mocha": "10.0.0", "nyc": "15.1.0", "safe-buffer": "5.2.1", "supertest": "6.2.4" From 91a860bbf0dd67945afb3ade7803ced9d13bd011 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 23 Sep 2022 20:10:33 -0400 Subject: [PATCH 145/207] build: Node.js@16.17 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1afa375..8d624fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,7 +105,7 @@ jobs: node-version: "15.14" - name: Node.js 16.x - node-version: "16.16" + node-version: "16.17" - name: Node.js 17.x node-version: "17.9" From 0e3ddce9388ae61e639a6de9b5fa421c3591a59e Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 23 Sep 2022 20:11:57 -0400 Subject: [PATCH 146/207] Fix routing requests without method --- HISTORY.md | 5 +++++ lib/route.js | 9 +++++++-- test/route.js | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 9e2d8be..5e42df5 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * Fix routing requests without method + 1.3.7 / 2022-04-28 ================== diff --git a/lib/route.js b/lib/route.js index c82a3cc..1918e46 100644 --- a/lib/route.js +++ b/lib/route.js @@ -61,7 +61,9 @@ Route.prototype._handles_method = function _handles_method(method) { } // normalize name - var name = method.toLowerCase() + var name = typeof method === 'string' + ? method.toLowerCase() + : method if (name === 'head' && !this.methods['head']) { name = 'get' @@ -106,7 +108,10 @@ Route.prototype.dispatch = function dispatch(req, res, done) { return done() } - var method = req.method.toLowerCase() + var method = typeof req.method === 'string' + ? req.method.toLowerCase() + : req.method + if (method === 'head' && !this.methods['head']) { method = 'get' } diff --git a/test/route.js b/test/route.js index ba00fec..6a97ec0 100644 --- a/test/route.js +++ b/test/route.js @@ -44,6 +44,30 @@ describe('Router', function () { .expect(404, cb) }) + it('should route without method', function (done) { + var router = new Router() + var route = router.route('/foo') + var server = createServer(function (req, res, next) { + req.method = undefined + router(req, res, next) + }) + + route.post(createHitHandle(1)) + route.all(createHitHandle(2)) + route.get(createHitHandle(3)) + + router.get('/foo', createHitHandle(4)) + router.use(saw) + + request(server) + .get('/foo') + .expect(shouldNotHitHandle(1)) + .expect(shouldHitHandle(2)) + .expect(shouldNotHitHandle(3)) + .expect(shouldNotHitHandle(4)) + .expect(200, 'saw undefined /foo', done) + }) + it('should stack', function (done) { var cb = after(3, done) var router = new Router() From df7ccba3722605e8b630e009e2f50f5705ad629b Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 23 Sep 2022 20:13:28 -0400 Subject: [PATCH 147/207] build: eslint@8.24.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 23a8fe7..ee39c93 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "8.23.1", + "eslint": "8.24.0", "eslint-plugin-markdown": "3.0.0", "finalhandler": "1.2.0", "mocha": "10.0.0", From f76ecfd32f0a4a1f036058c3390162355fec73bf Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 23 Sep 2022 20:16:59 -0400 Subject: [PATCH 148/207] build: Node.js@18.9 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d624fe..5a712be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -111,7 +111,7 @@ jobs: node-version: "17.9" - name: Node.js 18.x - node-version: "18.7" + node-version: "18.9" steps: - uses: actions/checkout@v2 From 5a99eb6c84e518947bab263f7b359cc9be1543c5 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 25 Oct 2022 19:33:15 -0400 Subject: [PATCH 149/207] build: supertest@6.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ee39c93..a904e95 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "mocha": "10.0.0", "nyc": "15.1.0", "safe-buffer": "5.2.1", - "supertest": "6.2.4" + "supertest": "6.3.1" }, "files": [ "lib/", From 806dfe51b735cfc5ea19329aa6dce50ad67ebf21 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Nov 2022 23:40:06 -0400 Subject: [PATCH 150/207] build: Node.js@14.21 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a712be..f3c611b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: npm-i: mocha@9.2.2 - name: Node.js 14.x - node-version: "14.20" + node-version: "14.21" - name: Node.js 15.x node-version: "15.14" From 7b0fad14fb6ebba56a36713fb0437af11354e52c Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 2 Nov 2022 23:42:15 -0400 Subject: [PATCH 151/207] build: Node.js@16.18 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3c611b..85c7fc5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,7 +105,7 @@ jobs: node-version: "15.14" - name: Node.js 16.x - node-version: "16.17" + node-version: "16.18" - name: Node.js 17.x node-version: "17.9" From a8d531bf6b9aa9ac886e3d16c06022b4cfba72c6 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Sat, 19 Nov 2022 21:54:26 -0500 Subject: [PATCH 152/207] build: eslint@8.28.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a904e95..5ec8b6d 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "8.24.0", + "eslint": "8.28.0", "eslint-plugin-markdown": "3.0.0", "finalhandler": "1.2.0", "mocha": "10.0.0", From 99b60b1993b95f41d65cbb0843b5eda6c6765081 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 1 Dec 2022 19:33:55 -0500 Subject: [PATCH 153/207] build: Node.js@18.12 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85c7fc5..46e2091 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -111,7 +111,7 @@ jobs: node-version: "17.9" - name: Node.js 18.x - node-version: "18.9" + node-version: "18.12" steps: - uses: actions/checkout@v2 From 5b4ceadc30185ee06ed980e2f012329458a3c320 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 1 Dec 2022 19:39:01 -0500 Subject: [PATCH 154/207] build: support Node.js 19.x --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46e2091..3d0e131 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,7 @@ jobs: - Node.js 16.x - Node.js 17.x - Node.js 18.x + - Node.js 19.x include: - name: Node.js 0.8 @@ -113,6 +114,9 @@ jobs: - name: Node.js 18.x node-version: "18.12" + - name: Node.js 19.x + node-version: "19.2" + steps: - uses: actions/checkout@v2 From 3e79ad912b69fde07405f0dd1950e01a6fdeca30 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 28 Dec 2022 20:01:44 -0500 Subject: [PATCH 155/207] build: mocha@10.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5ec8b6d..2369ff0 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "eslint": "8.28.0", "eslint-plugin-markdown": "3.0.0", "finalhandler": "1.2.0", - "mocha": "10.0.0", + "mocha": "10.2.0", "nyc": "15.1.0", "safe-buffer": "5.2.1", "supertest": "6.3.1" From 20b8fc66402856ce4390f0c6bac1fb58677ec1fe Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 28 Dec 2022 20:05:19 -0500 Subject: [PATCH 156/207] build: supertest@6.3.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2369ff0..740ac92 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "mocha": "10.2.0", "nyc": "15.1.0", "safe-buffer": "5.2.1", - "supertest": "6.3.1" + "supertest": "6.3.3" }, "files": [ "lib/", From ba19a6485fe09a6dc883be2a8c584bc966926350 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 24 Jan 2023 21:14:01 -0500 Subject: [PATCH 157/207] build: Node.js@16.19 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d0e131..7c046db 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,7 +106,7 @@ jobs: node-version: "15.14" - name: Node.js 16.x - node-version: "16.18" + node-version: "16.19" - name: Node.js 17.x node-version: "17.9" From 8cd3849cbbd43d4782b140b4c37c65090be63450 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 24 Jan 2023 21:14:13 -0500 Subject: [PATCH 158/207] build: Node.js@18.13 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c046db..533a46b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -112,7 +112,7 @@ jobs: node-version: "17.9" - name: Node.js 18.x - node-version: "18.12" + node-version: "18.13" - name: Node.js 19.x node-version: "19.2" From 6264a1d22f49c966b0b3f42a06e54cd209d7a8f7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 24 Jan 2023 21:14:45 -0500 Subject: [PATCH 159/207] build: eslint@8.32.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 740ac92..95f4d2d 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "8.28.0", + "eslint": "8.32.0", "eslint-plugin-markdown": "3.0.0", "finalhandler": "1.2.0", "mocha": "10.2.0", From 15d9a4857c0cbc0da8a510a1943b60f3e015a02e Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 24 Jan 2023 21:53:55 -0500 Subject: [PATCH 160/207] build: Node.js@19.5 --- .github/workflows/ci.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 533a46b..077d009 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,7 +115,7 @@ jobs: node-version: "18.13" - name: Node.js 19.x - node-version: "19.2" + node-version: "19.5" steps: - uses: actions/checkout@v2 @@ -133,7 +133,12 @@ jobs: dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH" - name: Configure npm - run: npm config set shrinkwrap false + run: | + if [[ "$(npm config get package-lock)" == "true" ]]; then + npm config set package-lock false + else + npm config set shrinkwrap false + fi - name: Remove npm module(s) ${{ matrix.npm-rm }} run: npm rm --silent --save-dev ${{ matrix.npm-rm }} From 5665cf7cdb0d690224fdf8e87ccd7a4c8e35fb81 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 23 Feb 2023 23:19:17 -0500 Subject: [PATCH 161/207] build: Node.js@19.7 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 077d009..6a8d231 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,7 +115,7 @@ jobs: node-version: "18.13" - name: Node.js 19.x - node-version: "19.5" + node-version: "19.7" steps: - uses: actions/checkout@v2 From f06b5f8440b3edaf3b33209e6f20459b0f69ef15 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 23 Feb 2023 23:22:09 -0500 Subject: [PATCH 162/207] build: Node.js@18.14 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a8d231..1e81f9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -112,7 +112,7 @@ jobs: node-version: "17.9" - name: Node.js 18.x - node-version: "18.13" + node-version: "18.14" - name: Node.js 19.x node-version: "19.7" From 14bc38f9f8e7f85140f34dbdf05fb6cf06cd697e Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 24 Feb 2023 11:30:58 -0500 Subject: [PATCH 163/207] build: eslint@8.34.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 95f4d2d..f0faacf 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "8.32.0", + "eslint": "8.34.0", "eslint-plugin-markdown": "3.0.0", "finalhandler": "1.2.0", "mocha": "10.2.0", From 33a76a9512ca0cc048c7c3bf7d284b061a4f16ef Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 24 Feb 2023 11:34:02 -0500 Subject: [PATCH 164/207] build: actions/checkout@v3 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e81f9c..fad8a39 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -118,7 +118,7 @@ jobs: node-version: "19.7" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install Node.js ${{ matrix.node-version }} shell: bash -eo pipefail -l {0} @@ -207,7 +207,7 @@ jobs: needs: test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install lcov shell: bash From b4ee44bff267b8b9236162ef58028309858ac997 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 24 Feb 2023 11:34:53 -0500 Subject: [PATCH 165/207] build: actions/upload-artifact@v3 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fad8a39..a507e1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -195,7 +195,7 @@ jobs: mv "./${{ matrix.name }}" "./coverage/${{ matrix.name }}" fi - name: Upload code coverage - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: steps.list_env.outputs.nyc != '' with: From 1f1dffdb49db38b0edd081db82fffc6bdcfde9dd Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 24 Feb 2023 11:36:26 -0500 Subject: [PATCH 166/207] build: use $GITHUB_OUTPUT for environment list --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a507e1c..a570a3c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,7 +170,7 @@ jobs: echo "node@$(node -v)" echo "npm@$(npm -v)" npm -s ls ||: - (npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print "::set-output name=" $2 "::" $3 }' + (npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print $2 "=" $3 }' >> "$GITHUB_OUTPUT" - name: Run tests shell: bash From ceddead15a8396364e2beab17792d133f0d7d045 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 24 Feb 2023 11:38:26 -0500 Subject: [PATCH 167/207] build: actions/download-artifact@v3 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a570a3c..dd384f4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -214,7 +214,7 @@ jobs: run: sudo apt-get -y install lcov - name: Collect coverage reports - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: coverage path: ./coverage From 86a5f765838d863419c75e80a4f1dda9759657b7 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 24 Feb 2023 11:39:26 -0500 Subject: [PATCH 168/207] 1.3.8 --- HISTORY.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 5e42df5..0ca0844 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,5 @@ -unreleased -========== +1.3.8 / 2023-02-24 +================== * Fix routing requests without method diff --git a/package.json b/package.json index f0faacf..5279b12 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "router", "description": "Simple middleware-style router", - "version": "1.3.7", + "version": "1.3.8", "author": "Douglas Christopher Wilson ", "contributors": [ "Blake Embrey " From 361202d7f89aea10666304aced526b855966b2e5 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sat, 16 Mar 2024 11:59:10 -0500 Subject: [PATCH 169/207] build: enable ci workflow trigger --- .github/workflows/ci.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd384f4..3fe1bd4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,13 +1,18 @@ name: ci on: -- pull_request -- push + workflow_dispatch: + push: + branches: + - master + pull_request: + types: [opened, synchronize, reopened, ready_for_review] jobs: test: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: name: - Node.js 0.8 @@ -77,11 +82,11 @@ jobs: - name: Node.js 8.x node-version: "8.17" - npm-i: mocha@7.2.0 + npm-i: mocha@7.2.0 nyc@14.1.1 - name: Node.js 9.x node-version: "9.11" - npm-i: mocha@7.2.0 + npm-i: mocha@7.2.0 nyc@14.1.1 - name: Node.js 10.x node-version: "10.24" From d40e4b0cef309d49e856217f968480b24c9f11fb Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sat, 16 Mar 2024 12:45:20 -0500 Subject: [PATCH 170/207] build: legacy-peer-deps in new node --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f308fb..18be98d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,18 +103,23 @@ jobs: - name: Node.js 15.x node-version: "15.14" + legacy-peer-deps: true - name: Node.js 16.x node-version: "16.19" + legacy-peer-deps: true - name: Node.js 17.x node-version: "17.9" + legacy-peer-deps: true - name: Node.js 18.x node-version: "18.14" + legacy-peer-deps: true - name: Node.js 19.x node-version: "19.7" + legacy-peer-deps: true steps: - uses: actions/checkout@v3 @@ -150,7 +155,7 @@ jobs: fi - name: Install Node.js dependencies - run: npm install + run: ${{ matrix.legacy-peer-deps && 'npm install --legacy-peer-deps' || 'npm install' }} - name: List environment id: list_env From 4835526ce05e287bc418acb78ce528b353398af1 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sat, 16 Mar 2024 12:47:52 -0500 Subject: [PATCH 171/207] lint: fix lint in ci --- lib/route.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/route.js b/lib/route.js index 7a22f55..2a17763 100644 --- a/lib/route.js +++ b/lib/route.js @@ -110,7 +110,7 @@ Route.prototype.dispatch = function dispatch (req, res, done) { ? req.method.toLowerCase() : req.method - if (method === 'head' && !this.methods['head']) { + if (method === 'head' && !this.methods.head) { method = 'get' } From 3415497c32fbd24d934d97a880968cc37558e5ac Mon Sep 17 00:00:00 2001 From: Nate Eagleson Date: Tue, 6 Jun 2023 16:33:20 -0400 Subject: [PATCH 172/207] Fix spelling error in test name Just noticed this skimming through the tests and figured I'd offer a quick fix. --- test/route.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/route.js b/test/route.js index 6a97ec0..2da349c 100644 --- a/test/route.js +++ b/test/route.js @@ -574,7 +574,7 @@ describe('Router', function () { .expect(200, {'0': 's', 'user': 'tj', 'op': 'edit'}, cb) }) - it('should work inside literal paranthesis', function (done) { + it('should work inside literal parentheses', function (done) { var router = new Router() var route = router.route('/:user\\(:op\\)') var server = createServer(router) From e14430a106a41af06af83808abf34ade49631347 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Wed, 20 Mar 2024 21:06:57 -0500 Subject: [PATCH 173/207] 2.0.0-beta.2 --- HISTORY.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 246fc47..e17bcc7 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,5 @@ -2.x -=== +2.0.0-beta.2 / 2024-03-20 +========================= This incorporates all changes after 1.3.5 up to 1.3.8. diff --git a/package.json b/package.json index 63d1f8b..1016e69 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "router", "description": "Simple middleware-style router", - "version": "2.0.0-beta.1", + "version": "2.0.0-beta.2", "author": "Douglas Christopher Wilson ", "contributors": [ "Blake Embrey " From 41b9278102f8848a8d016ae350c5e1e9e440004b Mon Sep 17 00:00:00 2001 From: Carlos Serrano Date: Sun, 2 Jun 2024 19:03:06 +0200 Subject: [PATCH 174/207] ci: add ossf scorecard pipeline (#116) PR-URL: https://github.com/pillarjs/router/pull/116 --- .github/workflows/scorecard.yml | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/scorecard.yml diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml new file mode 100644 index 0000000..3bfd85a --- /dev/null +++ b/.github/workflows/scorecard.yml @@ -0,0 +1,72 @@ +# This workflow uses actions that are not certified by GitHub. They are provided +# by a third-party and are governed by separate terms of service, privacy +# policy, and support documentation. + +name: Scorecard supply-chain security +on: + # For Branch-Protection check. Only the default branch is supported. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection + branch_protection_rule: + # To guarantee Maintained check is occasionally updated. See + # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained + schedule: + - cron: '16 21 * * 1' + push: + branches: [ "master" ] + +# Declare default permissions as read only. +permissions: read-all + +jobs: + analysis: + name: Scorecard analysis + runs-on: ubuntu-latest + permissions: + # Needed to upload the results to code-scanning dashboard. + security-events: write + # Needed to publish results and get a badge (see publish_results below). + id-token: write + # Uncomment the permissions below if installing in a private repository. + # contents: read + # actions: read + + steps: + - name: "Checkout code" + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + with: + persist-credentials: false + + - name: "Run analysis" + uses: ossf/scorecard-action@99c53751e09b9529366343771cc321ec74e9bd3d # v2.0.6 + with: + results_file: results.sarif + results_format: sarif + # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: + # - you want to enable the Branch-Protection check on a *public* repository, or + # - you are installing Scorecard on a *private* repository + # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. + # repo_token: ${{ secrets.SCORECARD_TOKEN }} + + # Public repositories: + # - Publish results to OpenSSF REST API for easy access by consumers + # - Allows the repository to include the Scorecard badge. + # - See https://github.com/ossf/scorecard-action#publishing-results. + # For private repositories: + # - `publish_results` will always be set to `false`, regardless + # of the value entered here. + publish_results: true + + # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF + # format to the repository Actions tab. + - name: "Upload artifact" + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 + with: + name: SARIF file + path: results.sarif + retention-days: 5 + + # Upload the results to GitHub's code scanning dashboard. + - name: "Upload to code-scanning" + uses: github/codeql-action/upload-sarif@2f93e4319b2f04a2efc38fa7f78bd681bc3f7b2f # v2.23.2 + with: + sarif_file: results.sarif \ No newline at end of file From 11dd0b9996dc0626b3ff6036e0cf3537d9b18c8c Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sun, 1 Sep 2024 11:33:05 -0500 Subject: [PATCH 175/207] fix(ci)!: drop support for node <18 --- .github/workflows/ci.yml | 132 ++++++--------------------------------- HISTORY.md | 5 ++ 2 files changed, 25 insertions(+), 112 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18be98d..273bc58 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,15 @@ name: ci on: - workflow_dispatch: push: branches: - - master + - master + - '2.0' + paths-ignore: + - '*.md' pull_request: - types: [opened, synchronize, reopened, ready_for_review] + paths-ignore: + - '*.md' jobs: test: @@ -15,114 +18,35 @@ jobs: fail-fast: false matrix: name: - - Node.js 0.10 - - Node.js 0.12 - - io.js 1.x - - io.js 2.x - - io.js 3.x - - Node.js 4.x - - Node.js 5.x - - Node.js 6.x - - Node.js 7.x - - Node.js 8.x - - Node.js 9.x - - Node.js 10.x - - Node.js 11.x - - Node.js 12.x - - Node.js 13.x - - Node.js 14.x - - Node.js 15.x - - Node.js 16.x - - Node.js 17.x - Node.js 18.x - Node.js 19.x + - Node.js 20.x + - Node.js 21.x + - Node.js 22.x include: - - name: Node.js 0.10 - node-version: "0.10" - npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - - - name: Node.js 0.12 - node-version: "0.12" - npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - - - name: io.js 1.x - node-version: "1.8" - npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - - - name: io.js 2.x - node-version: "2.5" - npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - - - name: io.js 3.x - node-version: "3.3" - npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0 - - - name: Node.js 4.x - node-version: "4.9" - npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 - - - name: Node.js 5.x - node-version: "5.12" - npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2 - - - name: Node.js 6.x - node-version: "6.17" - npm-i: mocha@6.2.2 nyc@14.1.1 supertest@3.4.2 - - - name: Node.js 7.x - node-version: "7.10" - npm-i: mocha@6.2.2 nyc@14.1.1 supertest@6.1.6 - - - name: Node.js 8.x - node-version: "8.17" - npm-i: mocha@7.2.0 nyc@14.1.1 - - - name: Node.js 9.x - node-version: "9.11" - npm-i: mocha@7.2.0 nyc@14.1.1 - - - name: Node.js 10.x - node-version: "10.24" - npm-i: mocha@8.4.0 - - - name: Node.js 11.x - node-version: "11.15" - npm-i: mocha@8.4.0 - - - name: Node.js 12.x - node-version: "12.22" - npm-i: mocha@9.2.2 - - - name: Node.js 13.x - node-version: "13.14" - npm-i: mocha@9.2.2 - - - name: Node.js 14.x - node-version: "14.21" - - - name: Node.js 15.x - node-version: "15.14" + - name: Node.js 18.x + node-version: "18" legacy-peer-deps: true - - name: Node.js 16.x - node-version: "16.19" + - name: Node.js 19.x + node-version: "19" legacy-peer-deps: true - - name: Node.js 17.x - node-version: "17.9" + - name: Node.js 20.x + node-version: "20" legacy-peer-deps: true - - name: Node.js 18.x - node-version: "18.14" + - name: Node.js 21.x + node-version: "21" legacy-peer-deps: true - - name: Node.js 19.x - node-version: "19.7" + - name: Node.js 22.x + node-version: "22" legacy-peer-deps: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Node.js ${{ matrix.node-version }} shell: bash -eo pipefail -l {0} @@ -138,22 +62,6 @@ jobs: npm config set shrinkwrap false fi - - name: Install npm module(s) ${{ matrix.npm-i }} - run: npm install --save-dev ${{ matrix.npm-i }} - if: matrix.npm-i != '' - - - name: Setup Node.js version-specific dependencies - shell: bash - run: | - # eslint for linting - # - remove on Node.js < 12 - if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 12 ]]; then - node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \ - grep -E '^eslint(-|$)' | \ - sort -r | \ - xargs -n1 npm rm --silent --save-dev - fi - - name: Install Node.js dependencies run: ${{ matrix.legacy-peer-deps && 'npm install --legacy-peer-deps' || 'npm install' }} diff --git a/HISTORY.md b/HISTORY.md index e17bcc7..2690521 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========================= + +* Drop support for node <18 + 2.0.0-beta.2 / 2024-03-20 ========================= From 04f8c3bfbadf6efed8c32e7df98961b5bd57b3a8 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sun, 1 Sep 2024 12:38:53 -0500 Subject: [PATCH 176/207] fix(ci): replace after with run-series to address flaky superagent behavior --- package.json | 2 +- test/param.js | 73 +++-- test/route.js | 395 ++++++++++++++----------- test/router.js | 787 ++++++++++++++++++++++++++++--------------------- 4 files changed, 720 insertions(+), 537 deletions(-) diff --git a/package.json b/package.json index 1016e69..66ba5af 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "utils-merge": "1.0.1" }, "devDependencies": { - "after": "0.8.2", "eslint": "8.34.0", "eslint-config-standard": "14.1.1", "eslint-plugin-import": "2.26.0", @@ -29,6 +28,7 @@ "finalhandler": "1.2.0", "mocha": "10.2.0", "nyc": "15.1.0", + "run-series": "^1.1.9", "safe-buffer": "5.2.1", "supertest": "6.3.3" }, diff --git a/test/param.js b/test/param.js index e2ca379..0b02b5c 100644 --- a/test/param.js +++ b/test/param.js @@ -1,5 +1,5 @@ -var after = require('after') +var series = require('run-series') var Router = require('..') var utils = require('./support/utils') @@ -35,7 +35,6 @@ describe('Router', function () { }) it('should map logic for a path param', function (done) { - var cb = after(2, done) var router = new Router() var server = createServer(router) @@ -49,13 +48,18 @@ describe('Router', function () { res.end('get user ' + req.params.id) }) - request(server) - .get('/user/2') - .expect(200, 'get user 2', cb) - - request(server) - .get('/user/bob') - .expect(200, 'get user NaN', cb) + series([ + function (cb) { + request(server) + .get('/user/2') + .expect(200, 'get user 2', cb) + }, + function (cb) { + request(server) + .get('/user/bob') + .expect(200, 'get user NaN', cb) + } + ], done) }) it('should allow chaining', function (done) { @@ -121,7 +125,6 @@ describe('Router', function () { }) it('should only invoke fn when necessary', function (done) { - var cb = after(2, done) var router = new Router() var server = createServer(router) @@ -137,14 +140,19 @@ describe('Router', function () { router.get('/user/:user', saw) router.put('/user/:id', saw) - request(server) - .get('/user/bob') - .expect(500, /Error: boom/, cb) - - request(server) - .put('/user/bob') - .expect('x-id', 'bob') - .expect(200, 'saw PUT /user/bob', cb) + series([ + function (cb) { + request(server) + .get('/user/bob') + .expect(500, /Error: boom/, cb) + }, + function (cb) { + request(server) + .put('/user/bob') + .expect('x-id', 'bob') + .expect(200, 'saw PUT /user/bob', cb) + } + ], done) }) it('should only invoke fn once per request', function (done) { @@ -300,7 +308,6 @@ describe('Router', function () { describe('next("route")', function () { it('should cause route with param to be skipped', function (done) { - var cb = after(3, done) var router = new Router() var server = createServer(router) @@ -326,17 +333,23 @@ describe('Router', function () { res.end('cannot get a new user') }) - request(server) - .get('/user/2') - .expect(200, 'get user 2', cb) - - request(server) - .get('/user/bob') - .expect(404, cb) - - request(server) - .get('/user/new') - .expect(400, 'cannot get a new user', cb) + series([ + function (cb) { + request(server) + .get('/user/2') + .expect(200, 'get user 2', cb) + }, + function (cb) { + request(server) + .get('/user/bob') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/user/new') + .expect(400, 'cannot get a new user', cb) + } + ], done) }) it('should invoke fn if path value differs', function (done) { diff --git a/test/route.js b/test/route.js index fcd6f8b..724f5d5 100644 --- a/test/route.js +++ b/test/route.js @@ -1,7 +1,7 @@ -var after = require('after') var Buffer = require('safe-buffer').Buffer var methods = require('methods') +var series = require('run-series') var Router = require('..') var utils = require('./support/utils') @@ -25,7 +25,6 @@ describe('Router', function () { }) it('should respond to multiple methods', function (done) { - var cb = after(3, done) var router = new Router() var route = router.route('/foo') var server = createServer(router) @@ -33,17 +32,23 @@ describe('Router', function () { route.get(saw) route.post(saw) - request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) - - request(server) - .post('/foo') - .expect(200, 'saw POST /foo', cb) - - request(server) - .put('/foo') - .expect(404, cb) + series([ + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /foo', cb) + }, + function (cb) { + request(server) + .post('/foo') + .expect(200, 'saw POST /foo', cb) + }, + function (cb) { + request(server) + .put('/foo') + .expect(404, cb) + } + ], done) }) it('should route without method', function (done) { @@ -71,7 +76,6 @@ describe('Router', function () { }) it('should stack', function (done) { - var cb = after(3, done) var router = new Router() var route = router.route('/foo') var server = createServer(router) @@ -82,39 +86,49 @@ describe('Router', function () { router.use(saw) - request(server) - .get('/foo') - .expect('x-fn-2', 'hit') - .expect('x-fn-3', 'hit') - .expect(200, 'saw GET /foo', cb) - - request(server) - .post('/foo') - .expect('x-fn-1', 'hit') - .expect('x-fn-2', 'hit') - .expect(200, 'saw POST /foo', cb) - - request(server) - .put('/foo') - .expect('x-fn-2', 'hit') - .expect(200, 'saw PUT /foo', cb) + series([ + function (cb) { + request(server) + .get('/foo') + .expect('x-fn-2', 'hit') + .expect('x-fn-3', 'hit') + .expect(200, 'saw GET /foo', cb) + }, + function (cb) { + request(server) + .post('/foo') + .expect('x-fn-1', 'hit') + .expect('x-fn-2', 'hit') + .expect(200, 'saw POST /foo', cb) + }, + function (cb) { + request(server) + .put('/foo') + .expect('x-fn-2', 'hit') + .expect(200, 'saw PUT /foo', cb) + } + ], done) }) it('should not error on empty route', function (done) { - var cb = after(2, done) var router = new Router() var route = router.route('/foo') var server = createServer(router) assert.ok(route) - request(server) - .get('/foo') - .expect(404, cb) - - request(server) - .head('/foo') - .expect(404, cb) + series([ + function (cb) { + request(server) + .get('/foo') + .expect(404, cb) + }, + function (cb) { + request(server) + .head('/foo') + .expect(404, cb) + } + ], done) }) it('should not invoke singular error route', function (done) { @@ -169,24 +183,29 @@ describe('Router', function () { }) it('should respond to all methods', function (done) { - var cb = after(3, done) var router = new Router() var route = router.route('/foo') var server = createServer(router) route.all(saw) - request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) - - request(server) - .post('/foo') - .expect(200, 'saw POST /foo', cb) - - request(server) - .put('/foo') - .expect(200, 'saw PUT /foo', cb) + series([ + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /foo', cb) + }, + function (cb) { + request(server) + .post('/foo') + .expect(200, 'saw POST /foo', cb) + }, + function (cb) { + request(server) + .put('/foo') + .expect(200, 'saw PUT /foo', cb) + } + ], done) }) it('should accept multiple arguments', function (done) { @@ -238,6 +257,9 @@ describe('Router', function () { // CONNECT is tricky and supertest doesn't support it return } + if (method === 'query' && process.version.startsWith('v21')) { + return + } var body = method !== 'head' ? shouldHaveBody(Buffer.from('hello, world')) @@ -695,20 +717,24 @@ describe('Router', function () { }) it('should work following a partial capture group', function (done) { - var cb = after(2, done) var router = new Router() var route = router.route('/user(s?)/:user/:op') var server = createServer(router) route.all(sendParams) - request(server) - .get('/user/tj/edit') - .expect(200, { 0: '', user: 'tj', op: 'edit' }, cb) - - request(server) - .get('/users/tj/edit') - .expect(200, { 0: 's', user: 'tj', op: 'edit' }, cb) + series([ + function (cb) { + request(server) + .get('/user/tj/edit') + .expect(200, { 0: '', user: 'tj', op: 'edit' }, cb) + }, + function (cb) { + request(server) + .get('/users/tj/edit') + .expect(200, { 0: 's', user: 'tj', op: 'edit' }, cb) + } + ], done) }) it('should work inside literal paranthesis', function (done) { @@ -724,203 +750,240 @@ describe('Router', function () { }) it('should work within arrays', function (done) { - var cb = after(2, done) var router = new Router() var route = router.route(['/user/:user/poke', '/user/:user/pokes']) var server = createServer(router) route.all(sendParams) - - request(server) - .get('/user/tj/poke') - .expect(200, { user: 'tj' }, cb) - - request(server) - .get('/user/tj/pokes') - .expect(200, { user: 'tj' }, cb) + series([ + function (cb) { + request(server) + .get('/user/tj/poke') + .expect(200, { user: 'tj' }, cb) + }, + function (cb) { + request(server) + .get('/user/tj/pokes') + .expect(200, { user: 'tj' }, cb) + } + ], done) }) }) describe('using ":name?"', function () { it('should name an optional parameter', function (done) { - var cb = after(2, done) var router = new Router() var route = router.route('/:foo?') var server = createServer(router) route.all(sendParams) - - request(server) - .get('/bar') - .expect(200, { foo: 'bar' }, cb) - - request(server) - .get('/') - .expect(200, {}, cb) + series([ + function (cb) { + request(server) + .get('/bar') + .expect(200, { foo: 'bar' }, cb) + }, + function (cb) { + request(server) + .get('/') + .expect(200, {}, cb) + } + ], done) }) it('should work in any segment', function (done) { - var cb = after(2, done) var router = new Router() var route = router.route('/user/:foo?/delete') var server = createServer(router) route.all(sendParams) - - request(server) - .get('/user/bar/delete') - .expect(200, { foo: 'bar' }, cb) - - request(server) - .get('/user/delete') - .expect(200, {}, cb) + series([ + function (cb) { + request(server) + .get('/user/bar/delete') + .expect(200, { foo: 'bar' }, cb) + }, + function (cb) { + request(server) + .get('/user/delete') + .expect(200, {}, cb) + } + ], done) }) }) describe('using ":name*"', function () { it('should name a zero-or-more repeated parameter', function (done) { - var cb = after(3, done) var router = new Router() var route = router.route('/:foo*') var server = createServer(router) route.all(sendParams) - - request(server) - .get('/') - .expect(200, {}, cb) - - request(server) - .get('/bar') - .expect(200, { foo: 'bar' }, cb) - - request(server) - .get('/fizz/buzz') - .expect(200, { foo: 'fizz/buzz' }, cb) + series([ + function (cb) { + request(server) + .get('/') + .expect(200, {}, cb) + }, + function (cb) { + request(server) + .get('/bar') + .expect(200, { foo: 'bar' }, cb) + }, + function (cb) { + request(server) + .get('/fizz/buzz') + .expect(200, { foo: 'fizz/buzz' }, cb) + } + ], done) }) it('should work in any segment', function (done) { - var cb = after(3, done) var router = new Router() var route = router.route('/user/:foo*/delete') var server = createServer(router) route.all(sendParams) - - request(server) - .get('/user/delete') - .expect(200, {}, cb) - - request(server) - .get('/user/bar/delete') - .expect(200, { foo: 'bar' }, cb) - - request(server) - .get('/user/fizz/buzz/delete') - .expect(200, { foo: 'fizz/buzz' }, cb) + series([ + function (cb) { + request(server) + .get('/user/delete') + .expect(200, {}, cb) + }, + function (cb) { + request(server) + .get('/user/bar/delete') + .expect(200, { foo: 'bar' }, cb) + }, + function (cb) { + request(server) + .get('/user/fizz/buzz/delete') + .expect(200, { foo: 'fizz/buzz' }, cb) + } + ], done) }) }) describe('using ":name+"', function () { it('should name a one-or-more repeated parameter', function (done) { - var cb = after(3, done) var router = new Router() var route = router.route('/:foo+') var server = createServer(router) route.all(sendParams) - request(server) - .get('/') - .expect(404, cb) - - request(server) - .get('/bar') - .expect(200, { foo: 'bar' }, cb) - - request(server) - .get('/fizz/buzz') - .expect(200, { foo: 'fizz/buzz' }, cb) + series([ + function (cb) { + request(server) + .get('/') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/bar') + .expect(200, { foo: 'bar' }, cb) + }, + function (cb) { + request(server) + .get('/fizz/buzz') + .expect(200, { foo: 'fizz/buzz' }, cb) + } + ], done) }) it('should work in any segment', function (done) { - var cb = after(3, done) var router = new Router() var route = router.route('/user/:foo+/delete') var server = createServer(router) route.all(sendParams) - - request(server) - .get('/user/delete') - .expect(404, cb) - - request(server) - .get('/user/bar/delete') - .expect(200, { foo: 'bar' }, cb) - - request(server) - .get('/user/fizz/buzz/delete') - .expect(200, { foo: 'fizz/buzz' }, cb) + series([ + function (cb) { + request(server) + .get('/user/delete') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/user/bar/delete') + .expect(200, { foo: 'bar' }, cb) + }, + function (cb) { + request(server) + .get('/user/fizz/buzz/delete') + .expect(200, { foo: 'fizz/buzz' }, cb) + } + ], done) }) }) describe('using ":name(regexp)"', function () { it('should limit capture group to regexp match', function (done) { - var cb = after(2, done) var router = new Router() var route = router.route('/:foo([0-9]+)') var server = createServer(router) route.all(sendParams) - request(server) - .get('/foo') - .expect(404, cb) - - request(server) - .get('/42') - .expect(200, { foo: '42' }, cb) + series([ + function (cb) { + request(server) + .get('/foo') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/42') + .expect(200, { foo: '42' }, cb) + } + ], done) }) }) describe('using "(regexp)"', function () { it('should add capture group using regexp', function (done) { - var cb = after(2, done) var router = new Router() var route = router.route('/page_([0-9]+)') var server = createServer(router) route.all(sendParams) - - request(server) - .get('/page_foo') - .expect(404, cb) - - request(server) - .get('/page_42') - .expect(200, { 0: '42' }, cb) + series([ + function (cb) { + request(server) + .get('/page_foo') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/page_42') + .expect(200, { 0: '42' }, cb) + } + ], done) }) it('should treat regexp as literal regexp', function (done) { - var cb = after(3, done) var router = new Router() var route = router.route('/([a-z]+:n[0-9]+)') var server = createServer(router) route.all(sendParams) - - request(server) - .get('/foo:bar') - .expect(404, cb) - - request(server) - .get('/foo:n') - .expect(404, cb) - - request(server) - .get('/foo:n42') - .expect(200, { 0: 'foo:n42' }, cb) + series([ + function (cb) { + request(server) + .get('/foo:bar') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/foo:n') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/foo:n42') + .expect(200, { 0: 'foo:n42' }, cb) + } + ], done) }) }) }) diff --git a/test/router.js b/test/router.js index 7af8186..433634f 100644 --- a/test/router.js +++ b/test/router.js @@ -1,7 +1,7 @@ -var after = require('after') var Buffer = require('safe-buffer').Buffer var methods = require('methods') +var series = require('run-series') var Router = require('..') var utils = require('./support/utils') @@ -44,90 +44,107 @@ describe('Router', function () { }) it('should respond to all methods', function (done) { - var cb = after(methods.length, done) var router = new Router() var server = createServer(router) router.all('/', helloWorld) - methods.forEach(function (method) { - if (method === 'connect') { - // CONNECT is tricky and supertest doesn't support it - return cb() + series(methods.map(function (method) { + return function (cb) { + if (method === 'connect') { + // CONNECT is tricky and supertest doesn't support it + return cb() + } + if (method === 'query' && process.version.startsWith('v21')) { + return cb() + } + + var body = method !== 'head' + ? shouldHaveBody(Buffer.from('hello, world')) + : shouldNotHaveBody() + + request(server)[method]('/') + .expect(200) + .expect(body) + .end(cb) } - - var body = method !== 'head' - ? shouldHaveBody(Buffer.from('hello, world')) - : shouldNotHaveBody() - - request(server)[method]('/') - .expect(200) - .expect(body) - .end(cb) - }) + }), done) }) it('should support array of paths', function (done) { - var cb = after(3, done) var router = new Router() var server = createServer(router) router.all(['/foo', '/bar'], saw) - - request(server) - .get('/') - .expect(404, cb) - - request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) - - request(server) - .get('/bar') - .expect(200, 'saw GET /bar', cb) + series([ + function (cb) { + request(server) + .get('/') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /foo', cb) + }, + function (cb) { + request(server) + .get('/bar') + .expect(200, 'saw GET /bar', cb) + } + ], done) }) it('should support regexp path', function (done) { - var cb = after(3, done) var router = new Router() var server = createServer(router) router.all(/^\/[a-z]oo$/, saw) - - request(server) - .get('/') - .expect(404, cb) - - request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) - - request(server) - .get('/zoo') - .expect(200, 'saw GET /zoo', cb) + series([ + function (cb) { + request(server) + .get('/') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /foo', cb) + }, + function (cb) { + request(server) + .get('/zoo') + .expect(200, 'saw GET /zoo', cb) + } + ], done) }) it('should support parameterized path', function (done) { - var cb = after(4, done) var router = new Router() var server = createServer(router) router.all('/:thing', saw) - - request(server) - .get('/') - .expect(404, cb) - - request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) - - request(server) - .get('/bar') - .expect(200, 'saw GET /bar', cb) - - request(server) - .get('/foo/bar') - .expect(404, cb) + series([ + function (cb) { + request(server) + .get('/') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /foo', cb) + }, + function (cb) { + request(server) + .get('/bar') + .expect(200, 'saw GET /bar', cb) + }, + function (cb) { + request(server) + .get('/foo/bar') + .expect(404, cb) + } + ], done) }) it('should not stack overflow with many registered routes', function (done) { @@ -166,113 +183,134 @@ describe('Router', function () { describe('with "caseSensitive" option', function () { it('should not match paths case-sensitively by default', function (done) { - var cb = after(3, done) var router = new Router() var server = createServer(router) router.all('/foo/bar', saw) - - request(server) - .get('/foo/bar') - .expect(200, 'saw GET /foo/bar', cb) - - request(server) - .get('/FOO/bar') - .expect(200, 'saw GET /FOO/bar', cb) - - request(server) - .get('/FOO/BAR') - .expect(200, 'saw GET /FOO/BAR', cb) + series([ + function (cb) { + request(server) + .get('/foo/bar') + .expect(200, 'saw GET /foo/bar', cb) + }, + function (cb) { + request(server) + .get('/FOO/bar') + .expect(200, 'saw GET /FOO/bar', cb) + }, + function (cb) { + request(server) + .get('/FOO/BAR') + .expect(200, 'saw GET /FOO/BAR', cb) + } + ], done) }) it('should not match paths case-sensitively when false', function (done) { - var cb = after(3, done) var router = new Router({ caseSensitive: false }) var server = createServer(router) router.all('/foo/bar', saw) - - request(server) - .get('/foo/bar') - .expect(200, 'saw GET /foo/bar', cb) - - request(server) - .get('/FOO/bar') - .expect(200, 'saw GET /FOO/bar', cb) - - request(server) - .get('/FOO/BAR') - .expect(200, 'saw GET /FOO/BAR', cb) + series([ + function (cb) { + request(server) + .get('/foo/bar') + .expect(200, 'saw GET /foo/bar', cb) + }, + function (cb) { + request(server) + .get('/FOO/bar') + .expect(200, 'saw GET /FOO/bar', cb) + }, + function (cb) { + request(server) + .get('/FOO/BAR') + .expect(200, 'saw GET /FOO/BAR', cb) + } + ], done) }) it('should match paths case-sensitively when true', function (done) { - var cb = after(3, done) var router = new Router({ caseSensitive: true }) var server = createServer(router) router.all('/foo/bar', saw) - - request(server) - .get('/foo/bar') - .expect(200, 'saw GET /foo/bar', cb) - - request(server) - .get('/FOO/bar') - .expect(404, cb) - - request(server) - .get('/FOO/BAR') - .expect(404, cb) + series([ + function (cb) { + request(server) + .get('/foo/bar') + .expect(200, 'saw GET /foo/bar', cb) + }, + function (cb) { + request(server) + .get('/FOO/bar') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/FOO/BAR') + .expect(404, cb) + } + ], done) }) }) describe('with "strict" option', function () { it('should accept optional trailing slashes by default', function (done) { - var cb = after(2, done) var router = new Router() var server = createServer(router) router.all('/foo', saw) - - request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) - - request(server) - .get('/foo/') - .expect(200, 'saw GET /foo/', cb) + series([ + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /foo', cb) + }, + function (cb) { + request(server) + .get('/foo/') + .expect(200, 'saw GET /foo/', cb) + } + ], done) }) it('should accept optional trailing slashes when false', function (done) { - var cb = after(2, done) var router = new Router({ strict: false }) var server = createServer(router) router.all('/foo', saw) - - request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) - - request(server) - .get('/foo/') - .expect(200, 'saw GET /foo/', cb) + series([ + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /foo', cb) + }, + function (cb) { + request(server) + .get('/foo/') + .expect(200, 'saw GET /foo/', cb) + } + ], done) }) it('should not accept optional trailing slashes when true', function (done) { - var cb = after(2, done) var router = new Router({ strict: true }) var server = createServer(router) router.all('/foo', saw) - - request(server) - .get('/foo') - .expect(200, 'saw GET /foo', cb) - - request(server) - .get('/foo/') - .expect(404, cb) + series([ + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /foo', cb) + }, + function (cb) { + request(server) + .get('/foo/') + .expect(404, cb) + } + ], done) }) }) }) @@ -282,6 +320,9 @@ describe('Router', function () { // CONNECT is tricky and supertest doesn't support it return } + if (method === 'query' && process.version.startsWith('v21')) { + return + } var body = method !== 'head' ? shouldHaveBody(Buffer.from('hello, world')) @@ -311,83 +352,97 @@ describe('Router', function () { }) it('should support array of paths', function (done) { - var cb = after(3, done) var router = new Router() var server = createServer(router) router[method](['/foo', '/bar'], createHitHandle(1), helloWorld) - - request(server)[method]('/') - .expect(404) - .expect(shouldNotHitHandle(1)) - .end(cb) - - request(server)[method]('/foo') - .expect(200) - .expect(shouldHitHandle(1)) - .expect(body) - .end(cb) - - request(server)[method]('/bar') - .expect(200) - .expect(shouldHitHandle(1)) - .expect(body) - .end(cb) + series([ + function (cb) { + request(server)[method]('/') + .expect(404) + .expect(shouldNotHitHandle(1)) + .end(cb) + }, + function (cb) { + request(server)[method]('/foo') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(body) + .end(cb) + }, + function (cb) { + request(server)[method]('/bar') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(body) + .end(cb) + } + ], done) }) it('should support regexp path', function (done) { - var cb = after(3, done) var router = new Router() var server = createServer(router) router[method](/^\/[a-z]oo$/, createHitHandle(1), helloWorld) - - request(server)[method]('/') - .expect(404) - .expect(shouldNotHitHandle(1)) - .end(cb) - - request(server)[method]('/foo') - .expect(200) - .expect(shouldHitHandle(1)) - .expect(body) - .end(cb) - - request(server)[method]('/zoo') - .expect(200) - .expect(shouldHitHandle(1)) - .expect(body) - .end(cb) + series([ + function (cb) { + request(server)[method]('/') + .expect(404) + .expect(shouldNotHitHandle(1)) + .end(cb) + }, + function (cb) { + request(server)[method]('/foo') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(body) + .end(cb) + }, + function (cb) { + request(server)[method]('/zoo') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(body) + .end(cb) + } + ], done) }) it('should support parameterized path', function (done) { - var cb = after(4, done) var router = new Router() var server = createServer(router) router[method]('/:thing', createHitHandle(1), helloWorld) - request(server)[method]('/') - .expect(404) - .expect(shouldNotHitHandle(1)) - .end(cb) - - request(server)[method]('/foo') - .expect(200) - .expect(shouldHitHandle(1)) - .expect(body) - .end(cb) - - request(server)[method]('/bar') - .expect(200) - .expect(shouldHitHandle(1)) - .expect(body) - .end(cb) - - request(server)[method]('/foo/bar') - .expect(404) - .expect(shouldNotHitHandle(1)) - .end(cb) + series([ + function (cb) { + request(server)[method]('/') + .expect(404) + .expect(shouldNotHitHandle(1)) + .end(cb) + }, + function (cb) { + request(server)[method]('/foo') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(body) + .end(cb) + }, + function (cb) { + request(server)[method]('/bar') + .expect(200) + .expect(shouldHitHandle(1)) + .expect(body) + .end(cb) + }, + function (cb) { + request(server)[method]('/foo/bar') + .expect(404) + .expect(shouldNotHitHandle(1)) + .end(cb) + } + ], done) }) it('should accept multiple arguments', function (done) { @@ -477,27 +532,33 @@ describe('Router', function () { }) it('should invoke function for all requests', function (done) { - var cb = after(4, done) var router = new Router() var server = createServer(router) router.use(saw) - request(server) - .get('/') - .expect(200, 'saw GET /', cb) - - request(server) - .put('/') - .expect(200, 'saw PUT /', cb) - - request(server) - .post('/foo') - .expect(200, 'saw POST /foo', cb) - - rawrequest(server) - .options('*') - .expect(200, 'saw OPTIONS *', cb) + series([ + function (cb) { + request(server) + .get('/') + .expect(200, 'saw GET /', cb) + }, + function (cb) { + request(server) + .put('/') + .expect(200, 'saw PUT /', cb) + }, + function (cb) { + request(server) + .post('/foo') + .expect(200, 'saw POST /foo', cb) + }, + function (cb) { + rawrequest(server) + .options('*') + .expect(200, 'saw OPTIONS *', cb) + } + ], done) }) it('should not invoke for blank URLs', function (done) { @@ -870,91 +931,111 @@ describe('Router', function () { }) it('should invoke when req.url starts with path', function (done) { - var cb = after(3, done) var router = new Router() var server = createServer(router) router.use('/foo', saw) - - request(server) - .get('/') - .expect(404, cb) - - request(server) - .post('/foo') - .expect(200, 'saw POST /', cb) - - request(server) - .post('/foo/bar') - .expect(200, 'saw POST /bar', cb) + series([ + function (cb) { + request(server) + .get('/') + .expect(404, cb) + }, + function (cb) { + request(server) + .post('/foo') + .expect(200, 'saw POST /', cb) + }, + function (cb) { + request(server) + .post('/foo/bar') + .expect(200, 'saw POST /bar', cb) + } + ], done) }) it('should match if path has trailing slash', function (done) { - var cb = after(3, done) var router = new Router() var server = createServer(router) router.use('/foo/', saw) - request(server) - .get('/') - .expect(404, cb) - - request(server) - .post('/foo') - .expect(200, 'saw POST /', cb) - - request(server) - .post('/foo/bar') - .expect(200, 'saw POST /bar', cb) + series([ + function (cb) { + request(server) + .get('/') + .expect(404, cb) + }, + function (cb) { + request(server) + .post('/foo') + .expect(200, 'saw POST /', cb) + }, + function (cb) { + request(server) + .post('/foo/bar') + .expect(200, 'saw POST /bar', cb) + } + ], done) }) it('should support array of paths', function (done) { - var cb = after(3, done) var router = new Router() var server = createServer(router) router.use(['/foo/', '/bar'], saw) - request(server) - .get('/') - .expect(404, cb) - - request(server) - .get('/foo') - .expect(200, 'saw GET /', cb) - - request(server) - .get('/bar') - .expect(200, 'saw GET /', cb) + series([ + function (cb) { + request(server) + .get('/') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /', cb) + }, + function (cb) { + request(server) + .get('/bar') + .expect(200, 'saw GET /', cb) + } + ], done) }) it('should support regexp path', function (done) { - var cb = after(5, done) var router = new Router() var server = createServer(router) router.use(/^\/[a-z]oo/, saw) - - request(server) - .get('/') - .expect(404, cb) - - request(server) - .get('/foo') - .expect(200, 'saw GET /', cb) - - request(server) - .get('/fooo') - .expect(404, cb) - - request(server) - .get('/zoo/bear') - .expect(200, 'saw GET /bear', cb) - - request(server) - .get('/get/zoo') - .expect(404, cb) + series([ + function (cb) { + request(server) + .get('/') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /', cb) + }, + function (cb) { + request(server) + .get('/fooo') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/zoo/bear') + .expect(200, 'saw GET /bear', cb) + }, + function (cb) { + request(server) + .get('/get/zoo') + .expect(404, cb) + } + ], done) }) it('should ensure regexp matches path prefix', function (done) { @@ -975,27 +1056,32 @@ describe('Router', function () { }) it('should support parameterized path', function (done) { - var cb = after(4, done) var router = new Router() var server = createServer(router) router.use('/:thing', saw) - - request(server) - .get('/') - .expect(404, cb) - - request(server) - .get('/foo') - .expect(200, 'saw GET /', cb) - - request(server) - .get('/bar') - .expect(200, 'saw GET /', cb) - - request(server) - .get('/foo/bar') - .expect(200, 'saw GET /bar', cb) + series([ + function (cb) { + request(server) + .get('/') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /', cb) + }, + function (cb) { + request(server) + .get('/bar') + .expect(200, 'saw GET /', cb) + }, + function (cb) { + request(server) + .get('/foo/bar') + .expect(200, 'saw GET /bar', cb) + } + ], done) }) it('should accept multiple arguments', function (done) { @@ -1013,113 +1099,134 @@ describe('Router', function () { describe('with "caseSensitive" option', function () { it('should not match paths case-sensitively by default', function (done) { - var cb = after(3, done) var router = new Router() var server = createServer(router) router.use('/foo', saw) - - request(server) - .get('/foo/bar') - .expect(200, 'saw GET /bar', cb) - - request(server) - .get('/FOO/bar') - .expect(200, 'saw GET /bar', cb) - - request(server) - .get('/FOO/BAR') - .expect(200, 'saw GET /BAR', cb) + series([ + function (cb) { + request(server) + .get('/foo/bar') + .expect(200, 'saw GET /bar', cb) + }, + function (cb) { + request(server) + .get('/FOO/bar') + .expect(200, 'saw GET /bar', cb) + }, + function (cb) { + request(server) + .get('/FOO/BAR') + .expect(200, 'saw GET /BAR', cb) + } + ], done) }) it('should not match paths case-sensitively when false', function (done) { - var cb = after(3, done) var router = new Router({ caseSensitive: false }) var server = createServer(router) router.use('/foo', saw) - - request(server) - .get('/foo/bar') - .expect(200, 'saw GET /bar', cb) - - request(server) - .get('/FOO/bar') - .expect(200, 'saw GET /bar', cb) - - request(server) - .get('/FOO/BAR') - .expect(200, 'saw GET /BAR', cb) + series([ + function (cb) { + request(server) + .get('/foo/bar') + .expect(200, 'saw GET /bar', cb) + }, + function (cb) { + request(server) + .get('/FOO/bar') + .expect(200, 'saw GET /bar', cb) + }, + function (cb) { + request(server) + .get('/FOO/BAR') + .expect(200, 'saw GET /BAR', cb) + } + ], done) }) it('should match paths case-sensitively when true', function (done) { - var cb = after(3, done) var router = new Router({ caseSensitive: true }) var server = createServer(router) router.use('/foo', saw) - - request(server) - .get('/foo/bar') - .expect(200, 'saw GET /bar', cb) - - request(server) - .get('/FOO/bar') - .expect(404, cb) - - request(server) - .get('/FOO/BAR') - .expect(404, cb) + series([ + function (cb) { + request(server) + .get('/foo/bar') + .expect(200, 'saw GET /bar', cb) + }, + function (cb) { + request(server) + .get('/FOO/bar') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/FOO/BAR') + .expect(404, cb) + } + ], done) }) }) describe('with "strict" option', function () { it('should accept optional trailing slashes by default', function (done) { - var cb = after(2, done) var router = new Router() var server = createServer(router) router.use('/foo', saw) - - request(server) - .get('/foo') - .expect(200, 'saw GET /', cb) - - request(server) - .get('/foo/') - .expect(200, 'saw GET /', cb) + series([ + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /', cb) + }, + function (cb) { + request(server) + .get('/foo/') + .expect(200, 'saw GET /', cb) + } + ], done) }) it('should accept optional trailing slashes when false', function (done) { - var cb = after(2, done) var router = new Router({ strict: false }) var server = createServer(router) router.use('/foo', saw) - - request(server) - .get('/foo') - .expect(200, 'saw GET /', cb) - - request(server) - .get('/foo/') - .expect(200, 'saw GET /', cb) + series([ + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /', cb) + }, + function (cb) { + request(server) + .get('/foo/') + .expect(200, 'saw GET /', cb) + } + ], done) }) it('should accept optional trailing slashes when true', function (done) { - var cb = after(2, done) var router = new Router({ strict: true }) var server = createServer(router) router.use('/foo', saw) - - request(server) - .get('/foo') - .expect(200, 'saw GET /', cb) - - request(server) - .get('/foo/') - .expect(200, 'saw GET /', cb) + series([ + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /', cb) + }, + function (cb) { + request(server) + .get('/foo/') + .expect(200, 'saw GET /', cb) + } + ], done) }) }) From 95b5cb5bbb9dc8ee3c49e07b554a023946c61554 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sun, 1 Sep 2024 11:17:15 -0500 Subject: [PATCH 177/207] fix(lint): replace broken eslint config with standard --- .eslintignore | 2 - .eslintrc.yml | 19 -- index.js | 134 +++++++------- lib/layer.js | 32 ++-- lib/route.js | 44 ++--- package.json | 11 +- scripts/version-history.js | 24 +-- test/.eslintrc.yml | 2 - test/auto-head.js | 22 +-- test/auto-options.js | 38 ++-- test/fqdn-url.js | 30 ++-- test/param.js | 92 +++++----- test/req.params.js | 48 ++--- test/route.js | 332 +++++++++++++++++------------------ test/router.js | 350 ++++++++++++++++++------------------- test/support/utils.js | 45 +++-- 16 files changed, 598 insertions(+), 627 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.yml delete mode 100644 test/.eslintrc.yml diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 62562b7..0000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -coverage -node_modules diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 6d49a7d..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,19 +0,0 @@ -root: true -extends: - - standard - - plugin:markdown/recommended -plugins: - - markdown -overrides: - - files: '**/*.md' - processor: 'markdown/markdown' -rules: - eol-last: error - indent: - - error - - 2 - - SwitchCase: 1 - no-trailing-spaces: error - semi: - - error - - never diff --git a/index.js b/index.js index 4964516..747ff33 100644 --- a/index.js +++ b/index.js @@ -12,21 +12,21 @@ * @private */ -var flatten = require('array-flatten').flatten -var isPromise = require('is-promise') -var Layer = require('./lib/layer') -var methods = require('methods') -var mixin = require('utils-merge') -var parseUrl = require('parseurl') -var Route = require('./lib/route') -var setPrototypeOf = require('setprototypeof') +const flatten = require('array-flatten').flatten +const isPromise = require('is-promise') +const Layer = require('./lib/layer') +const methods = require('methods') +const mixin = require('utils-merge') +const parseUrl = require('parseurl') +const Route = require('./lib/route') +const setPrototypeOf = require('setprototypeof') /** * Module variables. * @private */ -var slice = Array.prototype.slice +const slice = Array.prototype.slice /** * Expose `Router`. @@ -53,7 +53,7 @@ function Router (options) { return new Router(options) } - var opts = options || {} + const opts = options || {} function router (req, res, next) { router.handle(req, res, next) @@ -128,7 +128,7 @@ Router.prototype.param = function param (name, fn) { throw new TypeError('argument fn must be a function') } - var params = this.params[name] + let params = this.params[name] if (!params) { params = this.params[name] = [] @@ -150,22 +150,22 @@ Router.prototype.handle = function handle (req, res, callback) { throw new TypeError('argument callback is required') } - var idx = 0 - var methods - var protohost = getProtohost(req.url) || '' - var removed = '' - var self = this - var slashAdded = false - var sync = 0 - var paramcalled = {} + let idx = 0 + let methods + const protohost = getProtohost(req.url) || '' + let removed = '' + const self = this + let slashAdded = false + let sync = 0 + const paramcalled = {} // middleware and routes - var stack = this.stack + const stack = this.stack // manage inter-router variables - var parentParams = req.params - var parentUrl = req.baseUrl || '' - var done = restore(callback, req, 'baseUrl', 'next', 'params') + const parentParams = req.params + const parentUrl = req.baseUrl || '' + let done = restore(callback, req, 'baseUrl', 'next', 'params') // setup next layer req.next = next @@ -183,7 +183,7 @@ Router.prototype.handle = function handle (req, res, callback) { next() function next (err) { - var layerError = err === 'route' + let layerError = err === 'route' ? null : err @@ -218,16 +218,16 @@ Router.prototype.handle = function handle (req, res, callback) { } // get pathname of request - var path = getPathname(req) + const path = getPathname(req) if (path == null) { return done(layerError) } // find next matching layer - var layer - var match - var route + let layer + let match + let route while (match !== true && idx < stack.length) { layer = stack[idx++] @@ -254,8 +254,8 @@ Router.prototype.handle = function handle (req, res, callback) { continue } - var method = req.method - var hasMethod = route._handlesMethod(method) + const method = req.method + const hasMethod = route._handlesMethod(method) // build up automatic options response if (!hasMethod && method === 'OPTIONS' && methods) { @@ -283,7 +283,7 @@ Router.prototype.handle = function handle (req, res, callback) { req.params = self.mergeParams ? mergeParams(layer.params, parentParams) : layer.params - var layerPath = layer.path + const layerPath = layer.path // this should be done for the layer processParams(self.params, layer, paramcalled, req, res, function (err) { @@ -308,7 +308,7 @@ Router.prototype.handle = function handle (req, res, callback) { } // Validate path breaks on a path separator - var c = path[layerPath.length] + const c = path[layerPath.length] if (c && c !== '/') { next(layerError) return @@ -355,13 +355,13 @@ Router.prototype.handle = function handle (req, res, callback) { */ Router.prototype.use = function use (handler) { - var offset = 0 - var path = '/' + let offset = 0 + let path = '/' // default path to '/' // disambiguate router.use([handler]) if (typeof handler !== 'function') { - var arg = handler + let arg = handler while (Array.isArray(arg) && arg.length !== 0) { arg = arg[0] @@ -374,21 +374,21 @@ Router.prototype.use = function use (handler) { } } - var callbacks = flatten(slice.call(arguments, offset)) + const callbacks = flatten(slice.call(arguments, offset)) if (callbacks.length === 0) { throw new TypeError('argument handler is required') } - for (var i = 0; i < callbacks.length; i++) { - var fn = callbacks[i] + for (let i = 0; i < callbacks.length; i++) { + const fn = callbacks[i] if (typeof fn !== 'function') { throw new TypeError('argument handler must be a function') } // add the middleware - var layer = new Layer(path, { + const layer = new Layer(path, { sensitive: this.caseSensitive, strict: false, end: false @@ -416,9 +416,9 @@ Router.prototype.use = function use (handler) { */ Router.prototype.route = function route (path) { - var route = new Route(path) + const route = new Route(path) - var layer = new Layer(path, { + const layer = new Layer(path, { sensitive: this.caseSensitive, strict: this.strict, end: true @@ -437,7 +437,7 @@ Router.prototype.route = function route (path) { // create Router#VERB functions methods.concat('all').forEach(function (method) { Router.prototype[method] = function (path) { - var route = this.route(path) + const route = this.route(path) route[method].apply(route, slice.call(arguments, 1)) return this } @@ -488,11 +488,11 @@ function getProtohost (url) { return undefined } - var searchIndex = url.indexOf('?') - var pathLength = searchIndex !== -1 + const searchIndex = url.indexOf('?') + const pathLength = searchIndex !== -1 ? searchIndex : url.length - var fqdnIndex = url.substring(0, pathLength).indexOf('://') + const fqdnIndex = url.substring(0, pathLength).indexOf('://') return fqdnIndex !== -1 ? url.substring(0, url.indexOf('/', 3 + fqdnIndex)) @@ -527,15 +527,15 @@ function mergeParams (params, parent) { } // make copy of parent for base - var obj = mixin({}, parent) + const obj = mixin({}, parent) // simple non-numeric merging if (!(0 in params) || !(0 in parent)) { return mixin(obj, params) } - var i = 0 - var o = 0 + let i = 0 + let o = 0 // determine numeric gap in params while (i in params) { @@ -568,20 +568,20 @@ function mergeParams (params, parent) { function processParams (params, layer, called, req, res, done) { // captured parameters from the layer, keys and values - var keys = layer.keys + const keys = layer.keys // fast track if (!keys || keys.length === 0) { return done() } - var i = 0 - var name - var paramIndex = 0 - var key - var paramVal - var paramCallbacks - var paramCalled + let i = 0 + let name + let paramIndex = 0 + let key + let paramVal + let paramCallbacks + let paramCalled // process params in order // param callbacks can be async @@ -626,7 +626,7 @@ function processParams (params, layer, called, req, res, done) { // single param callbacks function paramCallback (err) { - var fn = paramCallbacks[paramIndex++] + const fn = paramCallbacks[paramIndex++] // store updated value paramCalled.value = req.params[key.name] @@ -641,7 +641,7 @@ function processParams (params, layer, called, req, res, done) { if (!fn) return param() try { - var ret = fn(req, res, paramCallback, paramVal, key.name) + const ret = fn(req, res, paramCallback, paramVal, key.name) if (isPromise(ret)) { ret.then(null, function (error) { paramCallback(error || new Error('Rejected promise')) @@ -662,17 +662,17 @@ function processParams (params, layer, called, req, res, done) { */ function restore (fn, obj) { - var props = new Array(arguments.length - 2) - var vals = new Array(arguments.length - 2) + const props = new Array(arguments.length - 2) + const vals = new Array(arguments.length - 2) - for (var i = 0; i < props.length; i++) { + for (let i = 0; i < props.length; i++) { props[i] = arguments[i + 2] vals[i] = obj[props[i]] } return function () { // restore vals - for (var i = 0; i < props.length; i++) { + for (let i = 0; i < props.length; i++) { obj[props[i]] = vals[i] } @@ -687,15 +687,15 @@ function restore (fn, obj) { */ function sendOptionsResponse (res, methods) { - var options = Object.create(null) + const options = Object.create(null) // build unique method map - for (var i = 0; i < methods.length; i++) { + for (let i = 0; i < methods.length; i++) { options[methods[i]] = true } // construct the allow list - var allow = Object.keys(options).sort().join(', ') + const allow = Object.keys(options).sort().join(', ') // send response res.setHeader('Allow', allow) @@ -727,10 +727,10 @@ function trySendOptionsResponse (res, methods, next) { function wrap (old, fn) { return function proxy () { - var args = new Array(arguments.length + 1) + const args = new Array(arguments.length + 1) args[0] = old - for (var i = 0, len = arguments.length; i < len; i++) { + for (let i = 0, len = arguments.length; i < len; i++) { args[i + 1] = arguments[i] } diff --git a/lib/layer.js b/lib/layer.js index 73f7d69..a96eb10 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -12,16 +12,16 @@ * @private */ -var isPromise = require('is-promise') -var pathRegexp = require('path-to-regexp') +const isPromise = require('is-promise') +const pathRegexp = require('path-to-regexp') /** * Module variables. * @private */ -var hasOwnProperty = Object.prototype.hasOwnProperty -var TRAILING_SLASH_REGEXP = /\/+$/ +const hasOwnProperty = Object.prototype.hasOwnProperty +const TRAILING_SLASH_REGEXP = /\/+$/ /** * Expose `Layer`. @@ -34,7 +34,7 @@ function Layer (path, options, fn) { return new Layer(path, options, fn) } - var opts = options || {} + const opts = options || {} this.handle = fn this.keys = [] @@ -58,7 +58,7 @@ function Layer (path, options, fn) { */ Layer.prototype.handleError = function handleError (error, req, res, next) { - var fn = this.handle + const fn = this.handle if (fn.length !== 4) { // not a standard error handler @@ -67,7 +67,7 @@ Layer.prototype.handleError = function handleError (error, req, res, next) { try { // invoke function - var ret = fn(error, req, res, next) + const ret = fn(error, req, res, next) // wait for returned promise if (isPromise(ret)) { @@ -90,7 +90,7 @@ Layer.prototype.handleError = function handleError (error, req, res, next) { */ Layer.prototype.handleRequest = function handleRequest (req, res, next) { - var fn = this.handle + const fn = this.handle if (fn.length > 3) { // not a standard request handler @@ -99,7 +99,7 @@ Layer.prototype.handleRequest = function handleRequest (req, res, next) { try { // invoke function - var ret = fn(req, res, next) + const ret = fn(req, res, next) // wait for returned promise if (isPromise(ret)) { @@ -122,7 +122,7 @@ Layer.prototype.handleRequest = function handleRequest (req, res, next) { */ Layer.prototype.match = function match (path) { - var match + let match if (path != null) { // fast path non-ending match for / (any path matches) @@ -147,13 +147,13 @@ Layer.prototype.match = function match (path) { this.path = match[0] // iterate matches - var keys = this.keys - var params = this.params + const keys = this.keys + const params = this.params - for (var i = 1; i < match.length; i++) { - var key = keys[i - 1] - var prop = key.name - var val = decodeParam(match[i]) + for (let i = 1; i < match.length; i++) { + const key = keys[i - 1] + const prop = key.name + const val = decodeParam(match[i]) if (val !== undefined || !(hasOwnProperty.call(params, prop))) { params[prop] = val diff --git a/lib/route.js b/lib/route.js index 2a17763..c9c53e7 100644 --- a/lib/route.js +++ b/lib/route.js @@ -12,19 +12,19 @@ * @private */ -var flatten = require('array-flatten').flatten -var Layer = require('./layer') -var methods = require('methods') +const flatten = require('array-flatten').flatten +const Layer = require('./layer') +const methods = require('methods') /** * Module variables. * @private */ -var slice = Array.prototype.slice +const slice = Array.prototype.slice /* istanbul ignore next */ -var defer = typeof setImmediate === 'function' +const defer = typeof setImmediate === 'function' ? setImmediate : function (fn) { process.nextTick(fn.bind.apply(fn, arguments)) } @@ -59,7 +59,7 @@ Route.prototype._handlesMethod = function _handlesMethod (method) { } // normalize name - var name = typeof method === 'string' + let name = typeof method === 'string' ? method.toLowerCase() : method @@ -76,14 +76,14 @@ Route.prototype._handlesMethod = function _handlesMethod (method) { */ Route.prototype._methods = function _methods () { - var methods = Object.keys(this.methods) + const methods = Object.keys(this.methods) // append automatic head if (this.methods.get && !this.methods.head) { methods.push('head') } - for (var i = 0; i < methods.length; i++) { + for (let i = 0; i < methods.length; i++) { // make upper case methods[i] = methods[i].toUpperCase() } @@ -98,15 +98,15 @@ Route.prototype._methods = function _methods () { */ Route.prototype.dispatch = function dispatch (req, res, done) { - var idx = 0 - var stack = this.stack - var sync = 0 + let idx = 0 + const stack = this.stack + let sync = 0 if (stack.length === 0) { return done() } - var method = typeof req.method === 'string' + let method = typeof req.method === 'string' ? req.method.toLowerCase() : req.method @@ -139,8 +139,8 @@ Route.prototype.dispatch = function dispatch (req, res, done) { return defer(next, err) } - var layer - var match + let layer + let match // find next matching layer while (match !== true && idx < stack.length) { @@ -192,20 +192,20 @@ Route.prototype.dispatch = function dispatch (req, res, done) { */ Route.prototype.all = function all (handler) { - var callbacks = flatten(slice.call(arguments)) + const callbacks = flatten(slice.call(arguments)) if (callbacks.length === 0) { throw new TypeError('argument handler is required') } - for (var i = 0; i < callbacks.length; i++) { - var fn = callbacks[i] + for (let i = 0; i < callbacks.length; i++) { + const fn = callbacks[i] if (typeof fn !== 'function') { throw new TypeError('argument handler must be a function') } - var layer = Layer('/', {}, fn) + const layer = Layer('/', {}, fn) layer.method = undefined this.methods._all = true @@ -217,20 +217,20 @@ Route.prototype.all = function all (handler) { methods.forEach(function (method) { Route.prototype[method] = function (handler) { - var callbacks = flatten(slice.call(arguments)) + const callbacks = flatten(slice.call(arguments)) if (callbacks.length === 0) { throw new TypeError('argument handler is required') } - for (var i = 0; i < callbacks.length; i++) { - var fn = callbacks[i] + for (let i = 0; i < callbacks.length; i++) { + const fn = callbacks[i] if (typeof fn !== 'function') { throw new TypeError('argument handler must be a function') } - var layer = Layer('/', {}, fn) + const layer = Layer('/', {}, fn) layer.method = method this.methods[method] = true diff --git a/package.json b/package.json index 66ba5af..900cc9e 100644 --- a/package.json +++ b/package.json @@ -18,18 +18,13 @@ "utils-merge": "1.0.1" }, "devDependencies": { - "eslint": "8.34.0", - "eslint-config-standard": "14.1.1", - "eslint-plugin-import": "2.26.0", - "eslint-plugin-markdown": "3.0.0", - "eslint-plugin-node": "11.1.0", - "eslint-plugin-promise": "5.2.0", - "eslint-plugin-standard": "4.1.0", + "after": "0.8.2", "finalhandler": "1.2.0", "mocha": "10.2.0", "nyc": "15.1.0", "run-series": "^1.1.9", "safe-buffer": "5.2.1", + "standard": "^17.1.0", "supertest": "6.3.3" }, "files": [ @@ -44,7 +39,7 @@ "node": ">= 0.10" }, "scripts": { - "lint": "eslint .", + "lint": "standard", "test": "mocha --reporter spec --bail --check-leaks test/", "test-ci": "nyc --reporter=lcov --reporter=text npm test", "test-cov": "nyc --reporter=text npm test", diff --git a/scripts/version-history.js b/scripts/version-history.js index c58268a..b62d4e1 100644 --- a/scripts/version-history.js +++ b/scripts/version-history.js @@ -1,14 +1,14 @@ 'use strict' -var fs = require('fs') -var path = require('path') +const fs = require('fs') +const path = require('path') -var HISTORY_FILE_PATH = path.join(__dirname, '..', 'HISTORY.md') -var MD_HEADER_REGEXP = /^====*$/ -var VERSION = process.env.npm_package_version -var VERSION_PLACEHOLDER_REGEXP = /^(?:unreleased|(\d+\.)+x)$/ +const HISTORY_FILE_PATH = path.join(__dirname, '..', 'HISTORY.md') +const MD_HEADER_REGEXP = /^====*$/ +const VERSION = process.env.npm_package_version +const VERSION_PLACEHOLDER_REGEXP = /^(?:unreleased|(\d+\.)+x)$/ -var historyFileLines = fs.readFileSync(HISTORY_FILE_PATH, 'utf-8').split('\n') +const historyFileLines = fs.readFileSync(HISTORY_FILE_PATH, 'utf-8').split('\n') if (!MD_HEADER_REGEXP.test(historyFileLines[1])) { console.error('Missing header in HISTORY.md') @@ -21,7 +21,7 @@ if (!VERSION_PLACEHOLDER_REGEXP.test(historyFileLines[0])) { } if (historyFileLines[0].indexOf('x') !== -1) { - var versionCheckRegExp = new RegExp('^' + historyFileLines[0].replace('x', '.+') + '$') + const versionCheckRegExp = new RegExp('^' + historyFileLines[0].replace('x', '.+') + '$') if (!versionCheckRegExp.test(VERSION)) { console.error('Version %s does not match placeholder %s', VERSION, historyFileLines[0]) @@ -35,7 +35,7 @@ historyFileLines[1] = repeat('=', historyFileLines[0].length) fs.writeFileSync(HISTORY_FILE_PATH, historyFileLines.join('\n')) function getLocaleDate () { - var now = new Date() + const now = new Date() return zeroPad(now.getFullYear(), 4) + '-' + zeroPad(now.getMonth() + 1, 2) + '-' + @@ -43,9 +43,9 @@ function getLocaleDate () { } function repeat (str, length) { - var out = '' + let out = '' - for (var i = 0; i < length; i++) { + for (let i = 0; i < length; i++) { out += str } @@ -53,7 +53,7 @@ function repeat (str, length) { } function zeroPad (number, length) { - var num = number.toString() + let num = number.toString() while (num.length < length) { num = '0' + num diff --git a/test/.eslintrc.yml b/test/.eslintrc.yml deleted file mode 100644 index 9808c3b..0000000 --- a/test/.eslintrc.yml +++ /dev/null @@ -1,2 +0,0 @@ -env: - mocha: true diff --git a/test/auto-head.js b/test/auto-head.js index 2fd8580..e8fca8a 100644 --- a/test/auto-head.js +++ b/test/auto-head.js @@ -1,14 +1,14 @@ +const { it, describe } = require('mocha') +const Router = require('..') +const utils = require('./support/utils') -var Router = require('..') -var utils = require('./support/utils') - -var createServer = utils.createServer -var request = utils.request +const createServer = utils.createServer +const request = utils.request describe('HEAD', function () { it('should invoke get without head', function (done) { - var router = Router() - var server = createServer(router) + const router = Router() + const server = createServer(router) router.get('/users', sethit(1), saw) @@ -20,8 +20,8 @@ describe('HEAD', function () { }) it('should invoke head if prior to get', function (done) { - var router = Router() - var server = createServer(router) + const router = Router() + const server = createServer(router) router.head('/users', sethit(1), saw) router.get('/users', sethit(2), saw) @@ -35,14 +35,14 @@ describe('HEAD', function () { }) function saw (req, res) { - var msg = 'saw ' + req.method + ' ' + req.url + const msg = 'saw ' + req.method + ' ' + req.url res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) } function sethit (num) { - var name = 'x-fn-' + String(num) + const name = 'x-fn-' + String(num) return function hit (req, res, next) { res.setHeader(name, 'hit') next() diff --git a/test/auto-options.js b/test/auto-options.js index 9cfd429..b4bcfac 100644 --- a/test/auto-options.js +++ b/test/auto-options.js @@ -1,14 +1,14 @@ +const { it, describe } = require('mocha') +const Router = require('..') +const utils = require('./support/utils') -var Router = require('..') -var utils = require('./support/utils') - -var createServer = utils.createServer -var request = utils.request +const createServer = utils.createServer +const request = utils.request describe('OPTIONS', function () { it('should respond with defined routes', function (done) { - var router = Router() - var server = createServer(router) + const router = Router() + const server = createServer(router) router.delete('/', saw) router.get('/users', saw) @@ -22,8 +22,8 @@ describe('OPTIONS', function () { }) it('should not contain methods multiple times', function (done) { - var router = Router() - var server = createServer(router) + const router = Router() + const server = createServer(router) router.delete('/', saw) router.get('/users', saw) @@ -37,8 +37,8 @@ describe('OPTIONS', function () { }) it('should not include "all" routes', function (done) { - var router = Router() - var server = createServer(router) + const router = Router() + const server = createServer(router) router.get('/', saw) router.get('/users', saw) @@ -53,8 +53,8 @@ describe('OPTIONS', function () { }) it('should not respond if no matching path', function (done) { - var router = Router() - var server = createServer(router) + const router = Router() + const server = createServer(router) router.get('/users', saw) @@ -64,8 +64,8 @@ describe('OPTIONS', function () { }) it('should do nothing with explicit options route', function (done) { - var router = Router() - var server = createServer(router) + const router = Router() + const server = createServer(router) router.get('/users', saw) router.options('/users', saw) @@ -77,8 +77,8 @@ describe('OPTIONS', function () { describe('when error occurs in respone handler', function () { it('should pass error to callback', function (done) { - var router = Router() - var server = createServer(function hander (req, res, next) { + const router = Router() + const server = createServer(function hander (req, res, next) { res.writeHead(200) router(req, res, function (err) { res.end(String(Boolean(err))) @@ -95,14 +95,14 @@ describe('OPTIONS', function () { }) function saw (req, res) { - var msg = 'saw ' + req.method + ' ' + req.url + const msg = 'saw ' + req.method + ' ' + req.url res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) } function sethit (num) { - var name = 'x-fn-' + String(num) + const name = 'x-fn-' + String(num) return function hit (req, res, next) { res.setHeader(name, 'hit') next() diff --git a/test/fqdn-url.js b/test/fqdn-url.js index 3ad73b3..8db59c3 100644 --- a/test/fqdn-url.js +++ b/test/fqdn-url.js @@ -1,14 +1,14 @@ +const { it, describe } = require('mocha') +const Router = require('..') +const utils = require('./support/utils') -var Router = require('..') -var utils = require('./support/utils') - -var createServer = utils.createServer -var rawrequest = utils.rawrequest +const createServer = utils.createServer +const rawrequest = utils.rawrequest describe('FQDN url', function () { it('should not obscure FQDNs', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(saw) @@ -18,8 +18,8 @@ describe('FQDN url', function () { }) it('should strip/restore FQDN req.url', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/blog', setsaw(1)) router.use(saw) @@ -31,8 +31,8 @@ describe('FQDN url', function () { }) it('should ignore FQDN in search', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/proxy', setsaw(1)) router.use(saw) @@ -44,8 +44,8 @@ describe('FQDN url', function () { }) it('should ignore FQDN in path', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/proxy', setsaw(1)) router.use(saw) @@ -58,7 +58,7 @@ describe('FQDN url', function () { }) function setsaw (num) { - var name = 'x-saw-' + String(num) + const name = 'x-saw-' + String(num) return function hit (req, res, next) { res.setHeader(name, req.method + ' ' + req.url) next() @@ -66,7 +66,7 @@ function setsaw (num) { } function saw (req, res) { - var msg = 'saw ' + req.method + ' ' + req.url + const msg = 'saw ' + req.method + ' ' + req.url res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) diff --git a/test/param.js b/test/param.js index 0b02b5c..52fd006 100644 --- a/test/param.js +++ b/test/param.js @@ -1,42 +1,42 @@ +const { it, describe } = require('mocha') +const series = require('run-series') +const Router = require('..') +const utils = require('./support/utils') -var series = require('run-series') -var Router = require('..') -var utils = require('./support/utils') +const assert = utils.assert +const createHitHandle = utils.createHitHandle +const shouldHitHandle = utils.shouldHitHandle +const shouldNotHitHandle = utils.shouldNotHitHandle +const createServer = utils.createServer +const request = utils.request -var assert = utils.assert -var createHitHandle = utils.createHitHandle -var shouldHitHandle = utils.shouldHitHandle -var shouldNotHitHandle = utils.shouldNotHitHandle -var createServer = utils.createServer -var request = utils.request - -var describePromises = global.Promise ? describe : describe.skip +const describePromises = global.Promise ? describe : describe.skip describe('Router', function () { describe('.param(name, fn)', function () { it('should reject missing name', function () { - var router = new Router() + const router = new Router() assert.throws(router.param.bind(router), /argument name is required/) }) it('should reject bad name', function () { - var router = new Router() + const router = new Router() assert.throws(router.param.bind(router, 42), /argument name must be a string/) }) it('should reject missing fn', function () { - var router = new Router() + const router = new Router() assert.throws(router.param.bind(router, 'id'), /argument fn is required/) }) it('should reject bad fn', function () { - var router = new Router() + const router = new Router() assert.throws(router.param.bind(router, 'id', 42), /argument fn must be a function/) }) it('should map logic for a path param', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('id', function parseId (req, res, next, val) { req.params.id = Number(val) @@ -63,8 +63,8 @@ describe('Router', function () { }) it('should allow chaining', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('id', function parseId (req, res, next, val) { req.params.id = Number(val) @@ -87,8 +87,8 @@ describe('Router', function () { }) it('should automatically decode path value', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('user', function parseUser (req, res, next, user) { req.user = user @@ -106,8 +106,8 @@ describe('Router', function () { }) it('should 400 on invalid path value', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('user', function parseUser (req, res, next, user) { req.user = user @@ -125,8 +125,8 @@ describe('Router', function () { }) it('should only invoke fn when necessary', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('id', function parseId (req, res, next, val) { res.setHeader('x-id', val) @@ -156,8 +156,8 @@ describe('Router', function () { }) it('should only invoke fn once per request', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('user', function parseUser (req, res, next, user) { req.count = (req.count || 0) + 1 @@ -178,8 +178,8 @@ describe('Router', function () { }) it('should keep changes to req.params value', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('id', function parseUser (req, res, next, val) { req.count = (req.count || 0) + 1 @@ -202,8 +202,8 @@ describe('Router', function () { }) it('should invoke fn if path value differs', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('user', function parseUser (req, res, next, user) { req.count = (req.count || 0) + 1 @@ -225,8 +225,8 @@ describe('Router', function () { }) it('should catch exception in fn', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('user', function parseUser (req, res, next, user) { throw new Error('boom') @@ -243,8 +243,8 @@ describe('Router', function () { }) it('should catch exception in chained fn', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('user', function parseUser (req, res, next, user) { process.nextTick(next) @@ -266,8 +266,8 @@ describe('Router', function () { describePromises('promise support', function () { it('should pass rejected promise value', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('user', function parseUser (req, res, next, user) { return Promise.reject(new Error('boom')) @@ -284,8 +284,8 @@ describe('Router', function () { }) it('should pass rejected promise without value', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function createError (req, res, next) { return Promise.reject() // eslint-disable-line prefer-promise-reject-errors @@ -308,11 +308,11 @@ describe('Router', function () { describe('next("route")', function () { it('should cause route with param to be skipped', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('id', function parseId (req, res, next, val) { - var id = Number(val) + const id = Number(val) if (isNaN(id)) { return next('route') @@ -353,8 +353,8 @@ describe('Router', function () { }) it('should invoke fn if path value differs', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.param('user', function parseUser (req, res, next, user) { req.count = (req.count || 0) + 1 @@ -381,7 +381,7 @@ describe('Router', function () { }) function sethit (num) { - var name = 'x-fn-' + String(num) + const name = 'x-fn-' + String(num) return function hit (req, res, next) { res.setHeader(name, 'hit') next() @@ -389,7 +389,7 @@ function sethit (num) { } function saw (req, res) { - var msg = 'saw ' + req.method + ' ' + req.url + const msg = 'saw ' + req.method + ' ' + req.url res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) diff --git a/test/req.params.js b/test/req.params.js index 4a0e01b..e5b1b6b 100644 --- a/test/req.params.js +++ b/test/req.params.js @@ -1,14 +1,14 @@ +const { it, describe } = require('mocha') +const Router = require('..') +const utils = require('./support/utils') -var Router = require('..') -var utils = require('./support/utils') - -var createServer = utils.createServer -var request = utils.request +const createServer = utils.createServer +const request = utils.request describe('req.params', function () { it('should default to empty object', function (done) { - var router = Router() - var server = createServer(router) + const router = Router() + const server = createServer(router) router.get('/', sawParams) @@ -18,8 +18,8 @@ describe('req.params', function () { }) it('should not exist outside the router', function (done) { - var router = Router() - var server = createServer(function (req, res, next) { + const router = Router() + const server = createServer(function (req, res, next) { router(req, res, function (err) { if (err) return next(err) sawParams(req, res) @@ -35,8 +35,8 @@ describe('req.params', function () { }) it('should overwrite value outside the router', function (done) { - var router = Router() - var server = createServer(function (req, res, next) { + const router = Router() + const server = createServer(function (req, res, next) { req.params = { foo: 'bar' } router(req, res, done) }) @@ -49,8 +49,8 @@ describe('req.params', function () { }) it('should restore previous value outside the router', function (done) { - var router = Router() - var server = createServer(function (req, res, next) { + const router = Router() + const server = createServer(function (req, res, next) { req.params = { foo: 'bar' } router(req, res, function (err) { @@ -69,8 +69,8 @@ describe('req.params', function () { describe('when "mergeParams: true"', function () { it('should merge outside object with params', function (done) { - var router = Router({ mergeParams: true }) - var server = createServer(function (req, res, next) { + const router = Router({ mergeParams: true }) + const server = createServer(function (req, res, next) { req.params = { foo: 'bar' } router(req, res, function (err) { @@ -88,8 +88,8 @@ describe('req.params', function () { }) it('should ignore non-object outside object', function (done) { - var router = Router({ mergeParams: true }) - var server = createServer(function (req, res, next) { + const router = Router({ mergeParams: true }) + const server = createServer(function (req, res, next) { req.params = 42 router(req, res, function (err) { @@ -107,8 +107,8 @@ describe('req.params', function () { }) it('should overwrite outside keys that are the same', function (done) { - var router = Router({ mergeParams: true }) - var server = createServer(function (req, res, next) { + const router = Router({ mergeParams: true }) + const server = createServer(function (req, res, next) { req.params = { foo: 'bar' } router(req, res, function (err) { @@ -127,8 +127,8 @@ describe('req.params', function () { describe('with numeric properties in req.params', function () { it('should merge numeric properties by offsetting', function (done) { - var router = Router({ mergeParams: true }) - var server = createServer(function (req, res, next) { + const router = Router({ mergeParams: true }) + const server = createServer(function (req, res, next) { req.params = { 0: 'foo', 1: 'bar' } router(req, res, function (err) { @@ -146,8 +146,8 @@ describe('req.params', function () { }) it('should merge with same numeric properties', function (done) { - var router = Router({ mergeParams: true }) - var server = createServer(function (req, res, next) { + const router = Router({ mergeParams: true }) + const server = createServer(function (req, res, next) { req.params = { 0: 'foo' } router(req, res, function (err) { @@ -168,7 +168,7 @@ describe('req.params', function () { }) function hitParams (num) { - var name = 'x-params-' + String(num) + const name = 'x-params-' + String(num) return function hit (req, res, next) { res.setHeader(name, JSON.stringify(req.params)) next() diff --git a/test/route.js b/test/route.js index 724f5d5..e32e1d4 100644 --- a/test/route.js +++ b/test/route.js @@ -1,33 +1,33 @@ - -var Buffer = require('safe-buffer').Buffer -var methods = require('methods') -var series = require('run-series') -var Router = require('..') -var utils = require('./support/utils') - -var assert = utils.assert -var createHitHandle = utils.createHitHandle -var createServer = utils.createServer -var request = utils.request -var shouldHaveBody = utils.shouldHaveBody -var shouldHitHandle = utils.shouldHitHandle -var shouldNotHaveBody = utils.shouldNotHaveBody -var shouldNotHitHandle = utils.shouldNotHitHandle - -var describePromises = global.Promise ? describe : describe.skip +const { it, describe } = require('mocha') +const Buffer = require('safe-buffer').Buffer +const methods = require('methods') +const series = require('run-series') +const Router = require('..') +const utils = require('./support/utils') + +const assert = utils.assert +const createHitHandle = utils.createHitHandle +const createServer = utils.createServer +const request = utils.request +const shouldHaveBody = utils.shouldHaveBody +const shouldHitHandle = utils.shouldHitHandle +const shouldNotHaveBody = utils.shouldNotHaveBody +const shouldNotHitHandle = utils.shouldNotHitHandle + +const describePromises = global.Promise ? describe : describe.skip describe('Router', function () { describe('.route(path)', function () { it('should return a new route', function () { - var router = new Router() - var route = router.route('/foo') + const router = new Router() + const route = router.route('/foo') assert.equal(route.path, '/foo') }) it('should respond to multiple methods', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.get(saw) route.post(saw) @@ -52,9 +52,9 @@ describe('Router', function () { }) it('should route without method', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(function (req, res, next) { + const router = new Router() + const route = router.route('/foo') + const server = createServer(function (req, res, next) { req.method = undefined router(req, res, next) }) @@ -76,9 +76,9 @@ describe('Router', function () { }) it('should stack', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.post(createHitHandle(1)) route.all(createHitHandle(2)) @@ -111,9 +111,9 @@ describe('Router', function () { }) it('should not error on empty route', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) assert.ok(route) @@ -132,9 +132,9 @@ describe('Router', function () { }) it('should not invoke singular error route', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(function handleError (err, req, res, next) { throw err || new Error('boom!') @@ -148,11 +148,11 @@ describe('Router', function () { it('should not stack overflow with a large sync stack', function (done) { this.timeout(5000) // long-running test - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) - for (var i = 0; i < 6000; i++) { + for (let i = 0; i < 6000; i++) { route.all(function (req, res, next) { next() }) } @@ -165,27 +165,27 @@ describe('Router', function () { describe('.all(...fn)', function () { it('should reject no arguments', function () { - var router = new Router() - var route = router.route('/') + const router = new Router() + const route = router.route('/') assert.throws(route.all.bind(route), /argument handler is required/) }) it('should reject empty array', function () { - var router = new Router() - var route = router.route('/') + const router = new Router() + const route = router.route('/') assert.throws(route.all.bind(route, []), /argument handler is required/) }) it('should reject invalid fn', function () { - var router = new Router() - var route = router.route('/') + const router = new Router() + const route = router.route('/') assert.throws(route.all.bind(route, 2), /argument handler must be a function/) }) it('should respond to all methods', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(saw) @@ -209,9 +209,9 @@ describe('Router', function () { }) it('should accept multiple arguments', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(createHitHandle(1), createHitHandle(2), helloWorld) @@ -223,9 +223,9 @@ describe('Router', function () { }) it('should accept single array of handlers', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all([createHitHandle(1), createHitHandle(2), helloWorld]) @@ -237,9 +237,9 @@ describe('Router', function () { }) it('should accept nested arrays of handlers', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all([[createHitHandle(1), createHitHandle(2)], createHitHandle(3)], helloWorld) @@ -261,15 +261,15 @@ describe('Router', function () { return } - var body = method !== 'head' + const body = method !== 'head' ? shouldHaveBody(Buffer.from('hello, world')) : shouldNotHaveBody() describe('.' + method + '(...fn)', function () { it('should respond to a ' + method.toUpperCase() + ' request', function (done) { - var router = new Router() - var route = router.route('/') - var server = createServer(router) + const router = new Router() + const route = router.route('/') + const server = createServer(router) route[method](helloWorld) @@ -280,27 +280,27 @@ describe('Router', function () { }) it('should reject no arguments', function () { - var router = new Router() - var route = router.route('/') + const router = new Router() + const route = router.route('/') assert.throws(route[method].bind(route), /argument handler is required/) }) it('should reject empty array', function () { - var router = new Router() - var route = router.route('/') + const router = new Router() + const route = router.route('/') assert.throws(route[method].bind(route, []), /argument handler is required/) }) it('should reject invalid fn', function () { - var router = new Router() - var route = router.route('/') + const router = new Router() + const route = router.route('/') assert.throws(route[method].bind(route, 2), /argument handler must be a function/) }) it('should accept multiple arguments', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route[method](createHitHandle(1), createHitHandle(2), helloWorld) @@ -313,9 +313,9 @@ describe('Router', function () { }) it('should accept single array of handlers', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route[method]([createHitHandle(1), createHitHandle(2), helloWorld]) @@ -328,9 +328,9 @@ describe('Router', function () { }) it('should accept nested arrays of handlers', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route[method]([[createHitHandle(1), createHitHandle(2)], createHitHandle(3)], helloWorld) @@ -347,9 +347,9 @@ describe('Router', function () { describe('error handling', function () { it('should handle errors from next(err)', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(function createError (req, res, next) { next(new Error('boom!')) @@ -368,9 +368,9 @@ describe('Router', function () { }) it('should handle errors thrown', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(function createError (req, res, next) { throw new Error('boom!') @@ -389,9 +389,9 @@ describe('Router', function () { }) it('should handle errors thrown in error handlers', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(function createError (req, res, next) { throw new Error('boom!') @@ -414,9 +414,9 @@ describe('Router', function () { describe('next("route")', function () { it('should invoke next handler', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.get(function handle (req, res, next) { res.setHeader('x-next', 'route') @@ -432,9 +432,9 @@ describe('Router', function () { }) it('should invoke next route', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.get(function handle (req, res, next) { res.setHeader('x-next', 'route') @@ -450,9 +450,9 @@ describe('Router', function () { }) it('should skip next handlers in route', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(createHitHandle(1)) route.get(function goNext (req, res, next) { @@ -472,9 +472,9 @@ describe('Router', function () { }) it('should not invoke error handlers', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(function goNext (req, res, next) { res.setHeader('x-next', 'route') @@ -495,9 +495,9 @@ describe('Router', function () { describe('next("router")', function () { it('should exit the router', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) function handle (req, res, next) { res.setHeader('x-next', 'router') @@ -516,9 +516,9 @@ describe('Router', function () { }) it('should not invoke error handlers', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(function goNext (req, res, next) { res.setHeader('x-next', 'router') @@ -544,9 +544,9 @@ describe('Router', function () { describePromises('promise support', function () { it('should pass rejected promise value', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(function createError (req, res, next) { return Promise.reject(new Error('boom!')) @@ -565,9 +565,9 @@ describe('Router', function () { }) it('should pass rejected promise without value', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(function createError (req, res, next) { return Promise.reject() // eslint-disable-line prefer-promise-reject-errors @@ -586,9 +586,9 @@ describe('Router', function () { }) it('should ignore resolved promise', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(function createError (req, res, next) { saw(req, res) @@ -606,9 +606,9 @@ describe('Router', function () { describe('error handling', function () { it('should pass rejected promise value', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(function createError (req, res, next) { return Promise.reject(new Error('boom!')) @@ -629,9 +629,9 @@ describe('Router', function () { }) it('should pass rejected promise without value', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(function createError (req, res, next) { return Promise.reject(new Error('boom!')) @@ -653,9 +653,9 @@ describe('Router', function () { }) it('should ignore resolved promise', function (done) { - var router = new Router() - var route = router.route('/foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/foo') + const server = createServer(router) route.all(function createError (req, res, next) { return Promise.reject(new Error('boom!')) @@ -681,9 +681,9 @@ describe('Router', function () { describe('path', function () { describe('using ":name"', function () { it('should name a capture group', function (done) { - var router = new Router() - var route = router.route('/:foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/:foo') + const server = createServer(router) route.all(sendParams) @@ -693,9 +693,9 @@ describe('Router', function () { }) it('should match single path segment', function (done) { - var router = new Router() - var route = router.route('/:foo') - var server = createServer(router) + const router = new Router() + const route = router.route('/:foo') + const server = createServer(router) route.all(sendParams) @@ -705,9 +705,9 @@ describe('Router', function () { }) it('should work multiple times', function (done) { - var router = new Router() - var route = router.route('/:foo/:bar') - var server = createServer(router) + const router = new Router() + const route = router.route('/:foo/:bar') + const server = createServer(router) route.all(sendParams) @@ -717,9 +717,9 @@ describe('Router', function () { }) it('should work following a partial capture group', function (done) { - var router = new Router() - var route = router.route('/user(s?)/:user/:op') - var server = createServer(router) + const router = new Router() + const route = router.route('/user(s?)/:user/:op') + const server = createServer(router) route.all(sendParams) @@ -738,9 +738,9 @@ describe('Router', function () { }) it('should work inside literal paranthesis', function (done) { - var router = new Router() - var route = router.route('/:user\\(:op\\)') - var server = createServer(router) + const router = new Router() + const route = router.route('/:user\\(:op\\)') + const server = createServer(router) route.all(sendParams) @@ -750,9 +750,9 @@ describe('Router', function () { }) it('should work within arrays', function (done) { - var router = new Router() - var route = router.route(['/user/:user/poke', '/user/:user/pokes']) - var server = createServer(router) + const router = new Router() + const route = router.route(['/user/:user/poke', '/user/:user/pokes']) + const server = createServer(router) route.all(sendParams) series([ @@ -772,9 +772,9 @@ describe('Router', function () { describe('using ":name?"', function () { it('should name an optional parameter', function (done) { - var router = new Router() - var route = router.route('/:foo?') - var server = createServer(router) + const router = new Router() + const route = router.route('/:foo?') + const server = createServer(router) route.all(sendParams) series([ @@ -792,9 +792,9 @@ describe('Router', function () { }) it('should work in any segment', function (done) { - var router = new Router() - var route = router.route('/user/:foo?/delete') - var server = createServer(router) + const router = new Router() + const route = router.route('/user/:foo?/delete') + const server = createServer(router) route.all(sendParams) series([ @@ -814,9 +814,9 @@ describe('Router', function () { describe('using ":name*"', function () { it('should name a zero-or-more repeated parameter', function (done) { - var router = new Router() - var route = router.route('/:foo*') - var server = createServer(router) + const router = new Router() + const route = router.route('/:foo*') + const server = createServer(router) route.all(sendParams) series([ @@ -839,9 +839,9 @@ describe('Router', function () { }) it('should work in any segment', function (done) { - var router = new Router() - var route = router.route('/user/:foo*/delete') - var server = createServer(router) + const router = new Router() + const route = router.route('/user/:foo*/delete') + const server = createServer(router) route.all(sendParams) series([ @@ -866,9 +866,9 @@ describe('Router', function () { describe('using ":name+"', function () { it('should name a one-or-more repeated parameter', function (done) { - var router = new Router() - var route = router.route('/:foo+') - var server = createServer(router) + const router = new Router() + const route = router.route('/:foo+') + const server = createServer(router) route.all(sendParams) @@ -892,9 +892,9 @@ describe('Router', function () { }) it('should work in any segment', function (done) { - var router = new Router() - var route = router.route('/user/:foo+/delete') - var server = createServer(router) + const router = new Router() + const route = router.route('/user/:foo+/delete') + const server = createServer(router) route.all(sendParams) series([ @@ -919,9 +919,9 @@ describe('Router', function () { describe('using ":name(regexp)"', function () { it('should limit capture group to regexp match', function (done) { - var router = new Router() - var route = router.route('/:foo([0-9]+)') - var server = createServer(router) + const router = new Router() + const route = router.route('/:foo([0-9]+)') + const server = createServer(router) route.all(sendParams) @@ -942,9 +942,9 @@ describe('Router', function () { describe('using "(regexp)"', function () { it('should add capture group using regexp', function (done) { - var router = new Router() - var route = router.route('/page_([0-9]+)') - var server = createServer(router) + const router = new Router() + const route = router.route('/page_([0-9]+)') + const server = createServer(router) route.all(sendParams) series([ @@ -962,9 +962,9 @@ describe('Router', function () { }) it('should treat regexp as literal regexp', function (done) { - var router = new Router() - var route = router.route('/([a-z]+:n[0-9]+)') - var server = createServer(router) + const router = new Router() + const route = router.route('/([a-z]+:n[0-9]+)') + const server = createServer(router) route.all(sendParams) series([ @@ -997,7 +997,7 @@ function helloWorld (req, res) { } function saw (req, res) { - var msg = 'saw ' + req.method + ' ' + req.url + const msg = 'saw ' + req.method + ' ' + req.url res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) diff --git a/test/router.js b/test/router.js index 433634f..01cc4ff 100644 --- a/test/router.js +++ b/test/router.js @@ -1,21 +1,21 @@ - -var Buffer = require('safe-buffer').Buffer -var methods = require('methods') -var series = require('run-series') -var Router = require('..') -var utils = require('./support/utils') - -var assert = utils.assert -var createHitHandle = utils.createHitHandle -var createServer = utils.createServer -var rawrequest = utils.rawrequest -var request = utils.request -var shouldHaveBody = utils.shouldHaveBody -var shouldHitHandle = utils.shouldHitHandle -var shouldNotHaveBody = utils.shouldNotHaveBody -var shouldNotHitHandle = utils.shouldNotHitHandle - -var describePromises = global.Promise ? describe : describe.skip +const { it, describe } = require('mocha') +const series = require('run-series') +const Buffer = require('safe-buffer').Buffer +const methods = require('methods') +const Router = require('..') +const utils = require('./support/utils') + +const assert = utils.assert +const createHitHandle = utils.createHitHandle +const createServer = utils.createServer +const rawrequest = utils.rawrequest +const request = utils.request +const shouldHaveBody = utils.shouldHaveBody +const shouldHitHandle = utils.shouldHitHandle +const shouldNotHaveBody = utils.shouldNotHaveBody +const shouldNotHitHandle = utils.shouldNotHitHandle + +const describePromises = global.Promise ? describe : describe.skip describe('Router', function () { it('should return a function', function () { @@ -27,25 +27,25 @@ describe('Router', function () { }) it('should reject missing callback', function () { - var router = new Router() + const router = new Router() assert.throws(function () { router({}, {}) }, /argument callback is required/) }) it('should invoke callback without "req.url"', function (done) { - var router = new Router() + const router = new Router() router.use(saw) router({}, {}, done) }) describe('.all(path, fn)', function () { it('should be chainable', function () { - var router = new Router() + const router = new Router() assert.equal(router.all('/', helloWorld), router) }) it('should respond to all methods', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.all('/', helloWorld) series(methods.map(function (method) { @@ -58,7 +58,7 @@ describe('Router', function () { return cb() } - var body = method !== 'head' + const body = method !== 'head' ? shouldHaveBody(Buffer.from('hello, world')) : shouldNotHaveBody() @@ -71,8 +71,8 @@ describe('Router', function () { }) it('should support array of paths', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.all(['/foo', '/bar'], saw) series([ @@ -95,8 +95,8 @@ describe('Router', function () { }) it('should support regexp path', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.all(/^\/[a-z]oo$/, saw) series([ @@ -119,8 +119,8 @@ describe('Router', function () { }) it('should support parameterized path', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.all('/:thing', saw) series([ @@ -150,10 +150,10 @@ describe('Router', function () { it('should not stack overflow with many registered routes', function (done) { this.timeout(5000) // long-running test - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) - for (var i = 0; i < 6000; i++) { + for (let i = 0; i < 6000; i++) { router.get('/thing' + i, helloWorld) } @@ -167,10 +167,10 @@ describe('Router', function () { it('should not stack overflow with a large sync stack', function (done) { this.timeout(5000) // long-running test - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) - for (var i = 0; i < 6000; i++) { + for (let i = 0; i < 6000; i++) { router.get('/foo', function (req, res, next) { next() }) } @@ -183,8 +183,8 @@ describe('Router', function () { describe('with "caseSensitive" option', function () { it('should not match paths case-sensitively by default', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.all('/foo/bar', saw) series([ @@ -207,8 +207,8 @@ describe('Router', function () { }) it('should not match paths case-sensitively when false', function (done) { - var router = new Router({ caseSensitive: false }) - var server = createServer(router) + const router = new Router({ caseSensitive: false }) + const server = createServer(router) router.all('/foo/bar', saw) series([ @@ -231,8 +231,8 @@ describe('Router', function () { }) it('should match paths case-sensitively when true', function (done) { - var router = new Router({ caseSensitive: true }) - var server = createServer(router) + const router = new Router({ caseSensitive: true }) + const server = createServer(router) router.all('/foo/bar', saw) series([ @@ -257,8 +257,8 @@ describe('Router', function () { describe('with "strict" option', function () { it('should accept optional trailing slashes by default', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.all('/foo', saw) series([ @@ -276,8 +276,8 @@ describe('Router', function () { }) it('should accept optional trailing slashes when false', function (done) { - var router = new Router({ strict: false }) - var server = createServer(router) + const router = new Router({ strict: false }) + const server = createServer(router) router.all('/foo', saw) series([ @@ -295,8 +295,8 @@ describe('Router', function () { }) it('should not accept optional trailing slashes when true', function (done) { - var router = new Router({ strict: true }) - var server = createServer(router) + const router = new Router({ strict: true }) + const server = createServer(router) router.all('/foo', saw) series([ @@ -324,19 +324,19 @@ describe('Router', function () { return } - var body = method !== 'head' + const body = method !== 'head' ? shouldHaveBody(Buffer.from('hello, world')) : shouldNotHaveBody() describe('.' + method + '(path, ...fn)', function () { it('should be chainable', function () { - var router = new Router() + const router = new Router() assert.equal(router[method]('/', helloWorld), router) }) it('should respond to a ' + method.toUpperCase() + ' request', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router[method]('/', helloWorld) @@ -347,13 +347,13 @@ describe('Router', function () { }) it('should reject invalid fn', function () { - var router = new Router() + const router = new Router() assert.throws(router[method].bind(router, '/', 2), /argument handler must be a function/) }) it('should support array of paths', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router[method](['/foo', '/bar'], createHitHandle(1), helloWorld) series([ @@ -381,8 +381,8 @@ describe('Router', function () { }) it('should support regexp path', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router[method](/^\/[a-z]oo$/, createHitHandle(1), helloWorld) series([ @@ -410,8 +410,8 @@ describe('Router', function () { }) it('should support parameterized path', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router[method]('/:thing', createHitHandle(1), helloWorld) @@ -446,8 +446,8 @@ describe('Router', function () { }) it('should accept multiple arguments', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router[method]('/', createHitHandle(1), createHitHandle(2), helloWorld) @@ -461,8 +461,8 @@ describe('Router', function () { describe('req.baseUrl', function () { it('should be empty', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router[method]('/foo', function handle (req, res) { res.setHeader('x-url-base', JSON.stringify(req.baseUrl)) @@ -477,8 +477,8 @@ describe('Router', function () { describe('req.route', function () { it('should be a Route', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router[method]('/foo', function handle (req, res) { res.setHeader('x-is-route', String(req.route instanceof Router.Route)) @@ -491,8 +491,8 @@ describe('Router', function () { }) it('should be the matched route', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router[method]('/foo', function handle (req, res) { res.setHeader('x-is-route', String(req.route.path === '/foo')) @@ -509,17 +509,17 @@ describe('Router', function () { describe('.use(...fn)', function () { it('should reject missing functions', function () { - var router = new Router() + const router = new Router() assert.throws(router.use.bind(router), /argument handler is required/) }) it('should reject empty array', function () { - var router = new Router() + const router = new Router() assert.throws(router.use.bind(router, []), /argument handler is required/) }) it('should reject non-functions', function () { - var router = new Router() + const router = new Router() assert.throws(router.use.bind(router, '/', 'hello'), /argument handler must be a function/) assert.throws(router.use.bind(router, '/', 5), /argument handler must be a function/) assert.throws(router.use.bind(router, '/', null), /argument handler must be a function/) @@ -527,13 +527,13 @@ describe('Router', function () { }) it('should be chainable', function () { - var router = new Router() + const router = new Router() assert.equal(router.use(helloWorld), router) }) it('should invoke function for all requests', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(saw) @@ -562,8 +562,8 @@ describe('Router', function () { }) it('should not invoke for blank URLs', function (done) { - var router = new Router() - var server = createServer(function hander (req, res, next) { + const router = new Router() + const server = createServer(function hander (req, res, next) { req.url = '' router(req, res, next) }) @@ -576,9 +576,9 @@ describe('Router', function () { }) it('should support another router', function (done) { - var inner = new Router() - var router = new Router() - var server = createServer(router) + const inner = new Router() + const router = new Router() + const server = createServer(router) inner.use(saw) router.use(inner) @@ -589,8 +589,8 @@ describe('Router', function () { }) it('should accept multiple arguments', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(createHitHandle(1), createHitHandle(2), helloWorld) @@ -602,8 +602,8 @@ describe('Router', function () { }) it('should accept single array of middleware', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use([createHitHandle(1), createHitHandle(2), helloWorld]) @@ -615,8 +615,8 @@ describe('Router', function () { }) it('should accept nested arrays of middleware', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use([[createHitHandle(1), createHitHandle(2)], createHitHandle(3)], helloWorld) @@ -629,8 +629,8 @@ describe('Router', function () { }) it('should not invoke singular error function', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function handleError (err, req, res, next) { throw err || new Error('boom!') @@ -644,10 +644,10 @@ describe('Router', function () { it('should not stack overflow with a large sync stack', function (done) { this.timeout(5000) // long-running test - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) - for (var i = 0; i < 6000; i++) { + for (let i = 0; i < 6000; i++) { router.use(function (req, res, next) { next() }) } @@ -660,8 +660,8 @@ describe('Router', function () { describe('error handling', function () { it('should invoke error function after next(err)', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function handle (req, res, next) { next(new Error('boom!')) @@ -675,8 +675,8 @@ describe('Router', function () { }) it('should invoke error function after throw err', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function handle (req, res, next) { throw new Error('boom!') @@ -690,8 +690,8 @@ describe('Router', function () { }) it('should not invoke error functions above function', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(sawError) @@ -707,8 +707,8 @@ describe('Router', function () { describe('next("route")', function () { it('should invoke next handler', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function handle (req, res, next) { res.setHeader('x-next', 'route') @@ -724,8 +724,8 @@ describe('Router', function () { }) it('should invoke next function', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) function goNext (req, res, next) { res.setHeader('x-next', 'route') @@ -743,8 +743,8 @@ describe('Router', function () { }) it('should not invoke error handlers', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function handle (req, res, next) { res.setHeader('x-next', 'route') @@ -762,8 +762,8 @@ describe('Router', function () { describe('next("router")', function () { it('should exit the router', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) function handle (req, res, next) { res.setHeader('x-next', 'router') @@ -781,8 +781,8 @@ describe('Router', function () { }) it('should not invoke error handlers', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function handle (req, res, next) { res.setHeader('x-next', 'router') @@ -800,8 +800,8 @@ describe('Router', function () { describePromises('promise support', function () { it('should pass rejected promise value', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function createError (req, res, next) { return Promise.reject(new Error('boom!')) @@ -815,8 +815,8 @@ describe('Router', function () { }) it('should pass rejected promise without value', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function createError (req, res, next) { return Promise.reject() // eslint-disable-line prefer-promise-reject-errors @@ -830,8 +830,8 @@ describe('Router', function () { }) it('should ignore resolved promise', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function createError (req, res, next) { saw(req, res) @@ -849,8 +849,8 @@ describe('Router', function () { describe('error handling', function () { it('should pass rejected promise value', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function createError (req, res, next) { return Promise.reject(new Error('boom!')) @@ -868,8 +868,8 @@ describe('Router', function () { }) it('should pass rejected promise without value', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function createError (req, res, next) { return Promise.reject() // eslint-disable-line prefer-promise-reject-errors @@ -887,8 +887,8 @@ describe('Router', function () { }) it('should ignore resolved promise', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(function createError (req, res, next) { return Promise.reject(new Error('boom!')) @@ -912,8 +912,8 @@ describe('Router', function () { describe('req.baseUrl', function () { it('should be empty', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(sawBase) @@ -926,13 +926,13 @@ describe('Router', function () { describe('.use(path, ...fn)', function () { it('should be chainable', function () { - var router = new Router() + const router = new Router() assert.equal(router.use('/', helloWorld), router) }) it('should invoke when req.url starts with path', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/foo', saw) series([ @@ -955,8 +955,8 @@ describe('Router', function () { }) it('should match if path has trailing slash', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/foo/', saw) @@ -980,8 +980,8 @@ describe('Router', function () { }) it('should support array of paths', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(['/foo/', '/bar'], saw) @@ -1005,8 +1005,8 @@ describe('Router', function () { }) it('should support regexp path', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(/^\/[a-z]oo/, saw) series([ @@ -1039,8 +1039,8 @@ describe('Router', function () { }) it('should ensure regexp matches path prefix', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use(/\/api.*/, createHitHandle(1)) router.use(/api/, createHitHandle(2)) @@ -1056,8 +1056,8 @@ describe('Router', function () { }) it('should support parameterized path', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/:thing', saw) series([ @@ -1085,8 +1085,8 @@ describe('Router', function () { }) it('should accept multiple arguments', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/foo', createHitHandle(1), createHitHandle(2), helloWorld) @@ -1099,8 +1099,8 @@ describe('Router', function () { describe('with "caseSensitive" option', function () { it('should not match paths case-sensitively by default', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/foo', saw) series([ @@ -1123,8 +1123,8 @@ describe('Router', function () { }) it('should not match paths case-sensitively when false', function (done) { - var router = new Router({ caseSensitive: false }) - var server = createServer(router) + const router = new Router({ caseSensitive: false }) + const server = createServer(router) router.use('/foo', saw) series([ @@ -1147,8 +1147,8 @@ describe('Router', function () { }) it('should match paths case-sensitively when true', function (done) { - var router = new Router({ caseSensitive: true }) - var server = createServer(router) + const router = new Router({ caseSensitive: true }) + const server = createServer(router) router.use('/foo', saw) series([ @@ -1173,8 +1173,8 @@ describe('Router', function () { describe('with "strict" option', function () { it('should accept optional trailing slashes by default', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/foo', saw) series([ @@ -1192,8 +1192,8 @@ describe('Router', function () { }) it('should accept optional trailing slashes when false', function (done) { - var router = new Router({ strict: false }) - var server = createServer(router) + const router = new Router({ strict: false }) + const server = createServer(router) router.use('/foo', saw) series([ @@ -1211,8 +1211,8 @@ describe('Router', function () { }) it('should accept optional trailing slashes when true', function (done) { - var router = new Router({ strict: true }) - var server = createServer(router) + const router = new Router({ strict: true }) + const server = createServer(router) router.use('/foo', saw) series([ @@ -1232,8 +1232,8 @@ describe('Router', function () { describe('next("route")', function () { it('should invoke next handler', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/foo', function handle (req, res, next) { res.setHeader('x-next', 'route') @@ -1249,8 +1249,8 @@ describe('Router', function () { }) it('should invoke next function', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) function goNext (req, res, next) { res.setHeader('x-next', 'route') @@ -1270,8 +1270,8 @@ describe('Router', function () { describe('req.baseUrl', function () { it('should contain the stripped path', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/foo', sawBase) @@ -1281,9 +1281,9 @@ describe('Router', function () { }) it('should contain the stripped path for multiple levels', function (done) { - var router1 = new Router() - var router2 = new Router() - var server = createServer(router1) + const router1 = new Router() + const router2 = new Router() + const server = createServer(router1) router1.use('/foo', router2) router2.use('/bar', sawBase) @@ -1294,11 +1294,11 @@ describe('Router', function () { }) it('should be altered correctly', function (done) { - var router = new Router() - var server = createServer(router) - var sub1 = new Router() - var sub2 = new Router() - var sub3 = new Router() + const router = new Router() + const server = createServer(router) + const sub1 = new Router() + const sub2 = new Router() + const sub3 = new Router() sub3.get('/zed', setsawBase(1)) @@ -1327,8 +1327,8 @@ describe('Router', function () { describe('req.url', function () { it('should strip path from req.url', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/foo', saw) @@ -1338,8 +1338,8 @@ describe('Router', function () { }) it('should restore req.url after stripping', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/foo', setsaw(1)) router.use(saw) @@ -1351,8 +1351,8 @@ describe('Router', function () { }) it('should strip/restore with trailing stash', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.use('/foo', setsaw(1)) router.use(saw) @@ -1367,8 +1367,8 @@ describe('Router', function () { describe('request rewriting', function () { it('should support altering req.method', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.put('/foo', createHitHandle(1)) router.post('/foo', createHitHandle(2), function (req, res, next) { @@ -1390,8 +1390,8 @@ describe('Router', function () { }) it('should support altering req.url', function (done) { - var router = new Router() - var server = createServer(router) + const router = new Router() + const server = createServer(router) router.get('/bar', createHitHandle(1)) router.get('/foo', createHitHandle(2), function (req, res, next) { @@ -1421,7 +1421,7 @@ function helloWorld (req, res) { } function setsaw (num) { - var name = 'x-saw-' + String(num) + const name = 'x-saw-' + String(num) return function saw (req, res, next) { res.setHeader(name, req.method + ' ' + req.url) next() @@ -1429,7 +1429,7 @@ function setsaw (num) { } function setsawBase (num) { - var name = 'x-saw-base-' + String(num) + const name = 'x-saw-base-' + String(num) return function sawBase (req, res, next) { res.setHeader(name, String(req.baseUrl)) next() @@ -1437,21 +1437,21 @@ function setsawBase (num) { } function saw (req, res) { - var msg = 'saw ' + req.method + ' ' + req.url + const msg = 'saw ' + req.method + ' ' + req.url res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) } function sawError (err, req, res, next) { - var msg = 'saw ' + err.name + ': ' + err.message + const msg = 'saw ' + err.name + ': ' + err.message res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) } function sawBase (req, res) { - var msg = 'saw ' + req.baseUrl + const msg = 'saw ' + req.baseUrl res.statusCode = 200 res.setHeader('Content-Type', 'text/plain') res.end(msg) diff --git a/test/support/utils.js b/test/support/utils.js index 30b2a5e..45ccb8a 100644 --- a/test/support/utils.js +++ b/test/support/utils.js @@ -1,10 +1,9 @@ - -var assert = require('assert') -var Buffer = require('safe-buffer').Buffer -var finalhandler = require('finalhandler') -var http = require('http') -var methods = require('methods') -var request = require('supertest') +const assert = require('assert') +const Buffer = require('safe-buffer').Buffer +const finalhandler = require('finalhandler') +const http = require('http') +const methods = require('methods') +const request = require('supertest') exports.assert = assert exports.createHitHandle = createHitHandle @@ -17,7 +16,7 @@ exports.shouldHitHandle = shouldHitHandle exports.shouldNotHitHandle = shouldNotHitHandle function createHitHandle (num) { - var name = 'x-fn-' + String(num) + const name = 'x-fn-' + String(num) return function hit (req, res, next) { res.setHeader(name, 'hit') next() @@ -31,10 +30,10 @@ function createServer (router) { } function rawrequest (server) { - var _headers = {} - var _method - var _path - var _test = {} + const _headers = {} + let _method + let _path + const _test = {} methods.forEach(function (method) { _test[method] = go.bind(null, method) @@ -46,7 +45,7 @@ function rawrequest (server) { return this } - var _server + let _server if (!server.address()) { _server = server.listen(0, onListening) @@ -56,25 +55,25 @@ function rawrequest (server) { onListening.call(server) function onListening () { - var addr = this.address() - var port = addr.port + const addr = this.address() + const port = addr.port - var req = http.request({ + const req = http.request({ host: '127.0.0.1', method: _method, path: _path, - port: port + port }) req.on('response', function (res) { - var buf = '' + let buf = '' res.setEncoding('utf8') res.on('data', function (s) { buf += s }) res.on('end', function () { - var err = null + let err = null try { - for (var key in _headers) { + for (const key in _headers) { assert.equal(res.headers[key], _headers[key]) } @@ -100,7 +99,7 @@ function rawrequest (server) { _path = path return { - expect: expect + expect } } @@ -109,7 +108,7 @@ function rawrequest (server) { function shouldHaveBody (buf) { return function (res) { - var body = !Buffer.isBuffer(res.body) + const body = !Buffer.isBuffer(res.body) ? Buffer.from(res.text) : res.body assert.ok(body, 'response has body') @@ -118,7 +117,7 @@ function shouldHaveBody (buf) { } function shouldHitHandle (num) { - var header = 'x-fn-' + String(num) + const header = 'x-fn-' + String(num) return function (res) { assert.equal(res.headers[header], 'hit', 'should hit handle ' + num) } From a57f761f3a30be64e1c4c741f7b6840ea0ce85cc Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sun, 1 Sep 2024 11:23:33 -0500 Subject: [PATCH 178/207] fix: add .git-blame-ignore-revs file for lint change --- .git-blame-ignore-revs | 1 + 1 file changed, 1 insertion(+) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..cfedcac --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1 @@ +29a69f3cf7cb5acbdde0a9151b885d46423b0c72 From f5a99b03c671ad88c354f96cd3ac7ccba6ad8269 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sun, 1 Sep 2024 13:52:54 -0500 Subject: [PATCH 179/207] fix(ci): remove legacy peer deps flag --- .github/workflows/ci.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 273bc58..96589d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,23 +27,18 @@ jobs: include: - name: Node.js 18.x node-version: "18" - legacy-peer-deps: true - name: Node.js 19.x node-version: "19" - legacy-peer-deps: true - name: Node.js 20.x node-version: "20" - legacy-peer-deps: true - name: Node.js 21.x node-version: "21" - legacy-peer-deps: true - name: Node.js 22.x node-version: "22" - legacy-peer-deps: true steps: - uses: actions/checkout@v4 @@ -63,7 +58,7 @@ jobs: fi - name: Install Node.js dependencies - run: ${{ matrix.legacy-peer-deps && 'npm install --legacy-peer-deps' || 'npm install' }} + run: npm install - name: List environment id: list_env From 30b42cbee88e7f9a19a75d2bf1538ea14a537963 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sat, 24 Aug 2024 12:08:47 -0500 Subject: [PATCH 180/207] feat!: path-to-regexp@^8.0.0 --- index.js | 16 +++--- lib/layer.js | 82 ++++++++++++++++++++--------- package.json | 3 +- test/req.params.js | 4 +- test/route.js | 126 ++++++--------------------------------------- test/router.js | 96 +++++++++++++++++++++++----------- 6 files changed, 151 insertions(+), 176 deletions(-) diff --git a/index.js b/index.js index 747ff33..0dbe740 100644 --- a/index.js +++ b/index.js @@ -576,7 +576,6 @@ function processParams (params, layer, called, req, res, done) { } let i = 0 - let name let paramIndex = 0 let key let paramVal @@ -596,10 +595,9 @@ function processParams (params, layer, called, req, res, done) { paramIndex = 0 key = keys[i++] - name = key.name - paramVal = req.params[name] - paramCallbacks = params[name] - paramCalled = called[name] + paramVal = req.params[key] + paramCallbacks = params[key] + paramCalled = called[key] if (paramVal === undefined || !paramCallbacks) { return param() @@ -609,13 +607,13 @@ function processParams (params, layer, called, req, res, done) { if (paramCalled && (paramCalled.match === paramVal || (paramCalled.error && paramCalled.error !== 'route'))) { // restore value - req.params[name] = paramCalled.value + req.params[key] = paramCalled.value // next param return param(paramCalled.error) } - called[name] = paramCalled = { + called[key] = paramCalled = { error: null, match: paramVal, value: paramVal @@ -629,7 +627,7 @@ function processParams (params, layer, called, req, res, done) { const fn = paramCallbacks[paramIndex++] // store updated value - paramCalled.value = req.params[key.name] + paramCalled.value = req.params[key] if (err) { // store error @@ -641,7 +639,7 @@ function processParams (params, layer, called, req, res, done) { if (!fn) return param() try { - const ret = fn(req, res, paramCallback, paramVal, key.name) + const ret = fn(req, res, paramCallback, paramVal, key) if (isPromise(ret)) { ret.then(null, function (error) { paramCallback(error || new Error('Rejected promise')) diff --git a/lib/layer.js b/lib/layer.js index a96eb10..e2fcba8 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -20,8 +20,8 @@ const pathRegexp = require('path-to-regexp') * @private */ -const hasOwnProperty = Object.prototype.hasOwnProperty const TRAILING_SLASH_REGEXP = /\/+$/ +const MATCHING_GROUP_REGEXP = /\((?:\?<(.*?)>)?(?!\?)/g /** * Expose `Layer`. @@ -41,10 +41,53 @@ function Layer (path, options, fn) { this.name = fn.name || '' this.params = undefined this.path = undefined - this.regexp = pathRegexp((opts.strict ? path : loosen(path)), this.keys, opts) + this.slash = path === '/' && opts.end === false + + function matcher (_path) { + if (_path instanceof RegExp) { + const keys = [] + let name = 0 + let m + // eslint-disable-next-line no-cond-assign + while (m = MATCHING_GROUP_REGEXP.exec(_path.source)) { + keys.push({ + name: m[1] || name++, + offset: m.index + }) + } + + return function regexpMatcher (p) { + const match = _path.exec(p) + if (!match) { + return false + } + + const params = {} + for (let i = 1; i < match.length; i++) { + const key = keys[i - 1] + const prop = key.name + const val = decodeParam(match[i]) + + if (val !== undefined) { + params[prop] = val + } + } + + return { + params, + path: match[0] + } + } + } - // set fast path flags - this.regexp._slash = path === '/' && opts.end === false + return pathRegexp.match((opts.strict ? _path : loosen(_path)), { + sensitive: opts.sensitive, + end: opts.end, + trailing: !opts.strict, + decode: decodeParam + }) + } + this.matchers = Array.isArray(path) ? path.map(matcher) : [matcher(path)] } /** @@ -126,14 +169,18 @@ Layer.prototype.match = function match (path) { if (path != null) { // fast path non-ending match for / (any path matches) - if (this.regexp._slash) { + if (this.slash) { this.params = {} this.path = '' return true } - // match the path - match = this.regexp.exec(path) + let i = 0 + while (!match && i < this.matchers.length) { + // match the path + match = this.matchers[i](path) + i++ + } } if (!match) { @@ -143,22 +190,9 @@ Layer.prototype.match = function match (path) { } // store values - this.params = {} - this.path = match[0] - - // iterate matches - const keys = this.keys - const params = this.params - - for (let i = 1; i < match.length; i++) { - const key = keys[i - 1] - const prop = key.name - const val = decodeParam(match[i]) - - if (val !== undefined || !(hasOwnProperty.call(params, prop))) { - params[prop] = val - } - } + this.params = match.params + this.path = match.path + this.keys = Object.keys(match.params) return true } @@ -192,7 +226,7 @@ function decodeParam (val) { * Loosens the given path for path-to-regexp matching. */ function loosen (path) { - if (path instanceof RegExp) { + if (path instanceof RegExp || path === '/') { return path } diff --git a/package.json b/package.json index 900cc9e..35de1ac 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "is-promise": "4.0.0", "methods": "~1.1.2", "parseurl": "~1.3.3", - "path-to-regexp": "3.2.0", + "path-to-regexp": "^8.0.0", "setprototypeof": "1.2.0", "utils-merge": "1.0.1" }, @@ -41,6 +41,7 @@ "scripts": { "lint": "standard", "test": "mocha --reporter spec --bail --check-leaks test/", + "test:debug": "mocha --reporter spec --bail --check-leaks test/ --inspect --inspect-brk", "test-ci": "nyc --reporter=lcov --reporter=text npm test", "test-cov": "nyc --reporter=text npm test", "version": "node scripts/version-history.js && git add HISTORY.md" diff --git a/test/req.params.js b/test/req.params.js index e5b1b6b..8eb4f63 100644 --- a/test/req.params.js +++ b/test/req.params.js @@ -137,7 +137,7 @@ describe('req.params', function () { }) }) - router.get('/(.*)', hitParams(1)) + router.get(/\/([^/]*)/, hitParams(1)) request(server) .get('/buzz') @@ -156,7 +156,7 @@ describe('req.params', function () { }) }) - router.get('/(.*)', hitParams(1)) + router.get(/\/([^/]*)/, hitParams(1)) request(server) .get('/bar') diff --git a/test/route.js b/test/route.js index e32e1d4..4d16ebf 100644 --- a/test/route.js +++ b/test/route.js @@ -716,27 +716,6 @@ describe('Router', function () { .expect(200, { foo: 'fizz', bar: 'buzz' }, done) }) - it('should work following a partial capture group', function (done) { - const router = new Router() - const route = router.route('/user(s?)/:user/:op') - const server = createServer(router) - - route.all(sendParams) - - series([ - function (cb) { - request(server) - .get('/user/tj/edit') - .expect(200, { 0: '', user: 'tj', op: 'edit' }, cb) - }, - function (cb) { - request(server) - .get('/users/tj/edit') - .expect(200, { 0: 's', user: 'tj', op: 'edit' }, cb) - } - ], done) - }) - it('should work inside literal paranthesis', function (done) { const router = new Router() const route = router.route('/:user\\(:op\\)') @@ -770,10 +749,10 @@ describe('Router', function () { }) }) - describe('using ":name?"', function () { + describe('using "{:name}"', function () { it('should name an optional parameter', function (done) { const router = new Router() - const route = router.route('/:foo?') + const route = router.route('{/:foo}') const server = createServer(router) route.all(sendParams) @@ -793,7 +772,7 @@ describe('Router', function () { it('should work in any segment', function (done) { const router = new Router() - const route = router.route('/user/:foo?/delete') + const route = router.route('/user{/:foo}/delete') const server = createServer(router) route.all(sendParams) @@ -812,10 +791,10 @@ describe('Router', function () { }) }) - describe('using ":name*"', function () { + describe('using "*name"', function () { it('should name a zero-or-more repeated parameter', function (done) { const router = new Router() - const route = router.route('/:foo*') + const route = router.route('{/*foo}') const server = createServer(router) route.all(sendParams) @@ -828,19 +807,19 @@ describe('Router', function () { function (cb) { request(server) .get('/bar') - .expect(200, { foo: 'bar' }, cb) + .expect(200, { foo: ['bar'] }, cb) }, function (cb) { request(server) .get('/fizz/buzz') - .expect(200, { foo: 'fizz/buzz' }, cb) + .expect(200, { foo: ['fizz', 'buzz'] }, cb) } ], done) }) it('should work in any segment', function (done) { const router = new Router() - const route = router.route('/user/:foo*/delete') + const route = router.route('/user{/*foo}/delete') const server = createServer(router) route.all(sendParams) @@ -853,74 +832,21 @@ describe('Router', function () { function (cb) { request(server) .get('/user/bar/delete') - .expect(200, { foo: 'bar' }, cb) - }, - function (cb) { - request(server) - .get('/user/fizz/buzz/delete') - .expect(200, { foo: 'fizz/buzz' }, cb) - } - ], done) - }) - }) - - describe('using ":name+"', function () { - it('should name a one-or-more repeated parameter', function (done) { - const router = new Router() - const route = router.route('/:foo+') - const server = createServer(router) - - route.all(sendParams) - - series([ - function (cb) { - request(server) - .get('/') - .expect(404, cb) - }, - function (cb) { - request(server) - .get('/bar') - .expect(200, { foo: 'bar' }, cb) - }, - function (cb) { - request(server) - .get('/fizz/buzz') - .expect(200, { foo: 'fizz/buzz' }, cb) - } - ], done) - }) - - it('should work in any segment', function (done) { - const router = new Router() - const route = router.route('/user/:foo+/delete') - const server = createServer(router) - - route.all(sendParams) - series([ - function (cb) { - request(server) - .get('/user/delete') - .expect(404, cb) - }, - function (cb) { - request(server) - .get('/user/bar/delete') - .expect(200, { foo: 'bar' }, cb) + .expect(200, { foo: ['bar'] }, cb) }, function (cb) { request(server) .get('/user/fizz/buzz/delete') - .expect(200, { foo: 'fizz/buzz' }, cb) + .expect(200, { foo: ['fizz', 'buzz'] }, cb) } ], done) }) }) - describe('using ":name(regexp)"', function () { + describe('using regular expression with param name "(?pattern)"', function () { it('should limit capture group to regexp match', function (done) { const router = new Router() - const route = router.route('/:foo([0-9]+)') + const route = router.route(/\/(?[0-9]+)/) const server = createServer(router) route.all(sendParams) @@ -943,7 +869,7 @@ describe('Router', function () { describe('using "(regexp)"', function () { it('should add capture group using regexp', function (done) { const router = new Router() - const route = router.route('/page_([0-9]+)') + const route = router.route(/\/page_([0-9]+)/) const server = createServer(router) route.all(sendParams) @@ -961,29 +887,11 @@ describe('Router', function () { ], done) }) - it('should treat regexp as literal regexp', function (done) { + it('should not treat regexp as literal regexp', function () { const router = new Router() - const route = router.route('/([a-z]+:n[0-9]+)') - const server = createServer(router) - - route.all(sendParams) - series([ - function (cb) { - request(server) - .get('/foo:bar') - .expect(404, cb) - }, - function (cb) { - request(server) - .get('/foo:n') - .expect(404, cb) - }, - function (cb) { - request(server) - .get('/foo:n42') - .expect(200, { 0: 'foo:n42' }, cb) - } - ], done) + assert.throws(function () { + router.route('/([a-z]+:n[0-9]+)') + }, /TypeError: Unexpected \( at/) }) }) }) diff --git a/test/router.js b/test/router.js index 01cc4ff..3c480d9 100644 --- a/test/router.js +++ b/test/router.js @@ -356,35 +356,7 @@ describe('Router', function () { const server = createServer(router) router[method](['/foo', '/bar'], createHitHandle(1), helloWorld) - series([ - function (cb) { - request(server)[method]('/') - .expect(404) - .expect(shouldNotHitHandle(1)) - .end(cb) - }, - function (cb) { - request(server)[method]('/foo') - .expect(200) - .expect(shouldHitHandle(1)) - .expect(body) - .end(cb) - }, - function (cb) { - request(server)[method]('/bar') - .expect(200) - .expect(shouldHitHandle(1)) - .expect(body) - .end(cb) - } - ], done) - }) - - it('should support regexp path', function (done) { - const router = new Router() - const server = createServer(router) - router[method](/^\/[a-z]oo$/, createHitHandle(1), helloWorld) series([ function (cb) { request(server)[method]('/') @@ -400,7 +372,7 @@ describe('Router', function () { .end(cb) }, function (cb) { - request(server)[method]('/zoo') + request(server)[method]('/bar') .expect(200) .expect(shouldHitHandle(1)) .expect(body) @@ -1008,7 +980,48 @@ describe('Router', function () { const router = new Router() const server = createServer(router) - router.use(/^\/[a-z]oo/, saw) + router.use(/^\/[a-z]oo$/, saw) + series([ + function (cb) { + request(server) + .get('/') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/foo') + .expect(200, 'saw GET /', cb) + }, + function (cb) { + request(server) + .get('/fooo') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/zoo/bear') + .expect(404, cb) + }, + function (cb) { + request(server) + .get('/get/zoo') + .expect(404, cb) + } + ], done) + }) + + it('should support regexp path with params', function (done) { + const router = new Router() + const server = createServer(router) + + router.use(/^\/([a-z]oo)$/, function (req, res, next) { + createHitHandle(req.params[0])(req, res, next) + }, saw) + + router.use(/^\/([a-z]oo)\/(?bear)$/, function (req, res, next) { + createHitHandle(req.params[0] + req.params.animal)(req, res, next) + }, saw) + series([ function (cb) { request(server) @@ -1018,6 +1031,13 @@ describe('Router', function () { function (cb) { request(server) .get('/foo') + .expect(shouldHitHandle('foo')) + .expect(200, 'saw GET /', cb) + }, + function (cb) { + request(server) + .get('/zoo') + .expect(shouldHitHandle('zoo')) .expect(200, 'saw GET /', cb) }, function (cb) { @@ -1028,7 +1048,8 @@ describe('Router', function () { function (cb) { request(server) .get('/zoo/bear') - .expect(200, 'saw GET /bear', cb) + .expect(shouldHitHandle('zoobear')) + .expect(200, cb) }, function (cb) { request(server) @@ -1293,6 +1314,19 @@ describe('Router', function () { .expect(200, 'saw /foo/bar', done) }) + it('should contain the stripped path for multiple levels with regular expressions', function (done) { + const router1 = new Router() + const router2 = new Router() + const server = createServer(router1) + + router1.use(/^\/foo/, router2) + router2.use(/^\/bar/, sawBase) + + request(server) + .get('/foo/bar/baz') + .expect(200, 'saw /foo/bar', done) + }) + it('should be altered correctly', function (done) { const router = new Router() const server = createServer(router) From 2e7fb67ad1b0c1cd2d9eb35c2244439c5c57891a Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Mon, 9 Sep 2024 17:42:24 -0500 Subject: [PATCH 181/207] 2.0.0 --- HISTORY.md | 12 ++++++++++-- package.json | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 2690521..ad7f247 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,7 +1,15 @@ -unreleased -========================= +2.0.0 / 2024-09-09 +================== * Drop support for node <18 +* deps: path-to-regexp@^8.0.0 + - Drop support for partial capture group `router.route('/user(s?)/:user/:op')` but still have optional non-capture `/user{s}/:user/:op` + - `:name?` becomes `{:name}` + - `:name*` becomes `*name`. + - The splat change also changes splat from strings to an array of strings + - Optional splats become `{*name}` + - `:name+` becomes `*name` and thus equivalent to `*name` so I dropped those tests + - Strings as regular expressions are fully removed, need to be converted to native regular expressions 2.0.0-beta.2 / 2024-03-20 ========================= diff --git a/package.json b/package.json index 35de1ac..c118ec6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "router", "description": "Simple middleware-style router", - "version": "2.0.0-beta.2", + "version": "2.0.0", "author": "Douglas Christopher Wilson ", "contributors": [ "Blake Embrey " From 550d542d8f7ffa270cf6363334eaa2d142b2337b Mon Sep 17 00:00:00 2001 From: Phillip Barta Date: Tue, 22 Oct 2024 20:25:49 +0200 Subject: [PATCH 182/207] refactor: use `Array.flat` instead of `array-flatten` package (#126) --- HISTORY.md | 5 +++++ index.js | 4 ++-- lib/route.js | 6 +++--- package.json | 1 - 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index ad7f247..3043cd1 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +================= + +* Use `Array.flat` instead of `array-flatten` package + 2.0.0 / 2024-09-09 ================== diff --git a/index.js b/index.js index 0dbe740..fac31f1 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,6 @@ * @private */ -const flatten = require('array-flatten').flatten const isPromise = require('is-promise') const Layer = require('./lib/layer') const methods = require('methods') @@ -27,6 +26,7 @@ const setPrototypeOf = require('setprototypeof') */ const slice = Array.prototype.slice +const flatten = Array.prototype.flat /** * Expose `Router`. @@ -374,7 +374,7 @@ Router.prototype.use = function use (handler) { } } - const callbacks = flatten(slice.call(arguments, offset)) + const callbacks = flatten.call(slice.call(arguments, offset), Infinity) if (callbacks.length === 0) { throw new TypeError('argument handler is required') diff --git a/lib/route.js b/lib/route.js index c9c53e7..5e9a778 100644 --- a/lib/route.js +++ b/lib/route.js @@ -12,7 +12,6 @@ * @private */ -const flatten = require('array-flatten').flatten const Layer = require('./layer') const methods = require('methods') @@ -22,6 +21,7 @@ const methods = require('methods') */ const slice = Array.prototype.slice +const flatten = Array.prototype.flat /* istanbul ignore next */ const defer = typeof setImmediate === 'function' @@ -192,7 +192,7 @@ Route.prototype.dispatch = function dispatch (req, res, done) { */ Route.prototype.all = function all (handler) { - const callbacks = flatten(slice.call(arguments)) + const callbacks = flatten.call(slice.call(arguments), Infinity) if (callbacks.length === 0) { throw new TypeError('argument handler is required') @@ -217,7 +217,7 @@ Route.prototype.all = function all (handler) { methods.forEach(function (method) { Route.prototype[method] = function (handler) { - const callbacks = flatten(slice.call(arguments)) + const callbacks = flatten.call(slice.call(arguments), Infinity) if (callbacks.length === 0) { throw new TypeError('argument handler is required') diff --git a/package.json b/package.json index c118ec6..153e133 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "license": "MIT", "repository": "pillarjs/router", "dependencies": { - "array-flatten": "3.0.0", "is-promise": "4.0.0", "methods": "~1.1.2", "parseurl": "~1.3.3", From 36ae18fdf81e3d4ee1c366d833d3a037b335a49d Mon Sep 17 00:00:00 2001 From: Phillip Barta Date: Tue, 22 Oct 2024 20:28:34 +0200 Subject: [PATCH 183/207] refactor: remove Object.setPrototypeOf polyfill (#125) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ulises Gascón --- HISTORY.md | 3 ++- index.js | 3 +-- package.json | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 3043cd1..f04ec61 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,7 @@ unreleased -================= +================== +* Remove `Object.setPrototypeOf` polyfill * Use `Array.flat` instead of `array-flatten` package 2.0.0 / 2024-09-09 diff --git a/index.js b/index.js index fac31f1..b806282 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,6 @@ const methods = require('methods') const mixin = require('utils-merge') const parseUrl = require('parseurl') const Route = require('./lib/route') -const setPrototypeOf = require('setprototypeof') /** * Module variables. @@ -60,7 +59,7 @@ function Router (options) { } // inherit from the correct prototype - setPrototypeOf(router, this) + Object.setPrototypeOf(router, this) router.caseSensitive = opts.caseSensitive router.mergeParams = opts.mergeParams diff --git a/package.json b/package.json index 153e133..de23500 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ "methods": "~1.1.2", "parseurl": "~1.3.3", "path-to-regexp": "^8.0.0", - "setprototypeof": "1.2.0", "utils-merge": "1.0.1" }, "devDependencies": { From 878b0e02365047f34c66b4a252e91597f8056635 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Wed, 23 Oct 2024 17:13:21 +0200 Subject: [PATCH 184/207] refactor: replace `methods` dependency with standard library (#127) --- HISTORY.md | 1 + lib/route.js | 5 ++++- package.json | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index f04ec61..5f69004 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,7 @@ unreleased * Remove `Object.setPrototypeOf` polyfill * Use `Array.flat` instead of `array-flatten` package +* Replace `methods` dependency with standard library 2.0.0 / 2024-09-09 ================== diff --git a/lib/route.js b/lib/route.js index 5e9a778..6f1b7cd 100644 --- a/lib/route.js +++ b/lib/route.js @@ -13,7 +13,7 @@ */ const Layer = require('./layer') -const methods = require('methods') +const { METHODS } = require('node:http') /** * Module variables. @@ -215,6 +215,9 @@ Route.prototype.all = function all (handler) { return this } + +const methods = METHODS.map((method) => method.toLowerCase()) + methods.forEach(function (method) { Route.prototype[method] = function (handler) { const callbacks = flatten.call(slice.call(arguments), Infinity) diff --git a/package.json b/package.json index de23500..cbbba3b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "repository": "pillarjs/router", "dependencies": { "is-promise": "4.0.0", - "methods": "~1.1.2", "parseurl": "~1.3.3", "path-to-regexp": "^8.0.0", "utils-merge": "1.0.1" From 0fe592eb7019b9d73cb15ecc8bca4baa9db8734d Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Tue, 29 Oct 2024 16:25:04 +0100 Subject: [PATCH 185/207] fix: replace `methods` imports everywhere (#130) --- index.js | 3 ++- lib/route.js | 4 +--- test/route.js | 2 +- test/router.js | 2 +- test/support/utils.js | 5 ++++- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index b806282..aa0cbc0 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ const isPromise = require('is-promise') const Layer = require('./lib/layer') -const methods = require('methods') +const { METHODS } = require('node:http') const mixin = require('utils-merge') const parseUrl = require('parseurl') const Route = require('./lib/route') @@ -26,6 +26,7 @@ const Route = require('./lib/route') const slice = Array.prototype.slice const flatten = Array.prototype.flat +const methods = METHODS.map((method) => method.toLowerCase()) /** * Expose `Router`. diff --git a/lib/route.js b/lib/route.js index 6f1b7cd..ec98414 100644 --- a/lib/route.js +++ b/lib/route.js @@ -22,6 +22,7 @@ const { METHODS } = require('node:http') const slice = Array.prototype.slice const flatten = Array.prototype.flat +const methods = METHODS.map((method) => method.toLowerCase()) /* istanbul ignore next */ const defer = typeof setImmediate === 'function' @@ -215,9 +216,6 @@ Route.prototype.all = function all (handler) { return this } - -const methods = METHODS.map((method) => method.toLowerCase()) - methods.forEach(function (method) { Route.prototype[method] = function (handler) { const callbacks = flatten.call(slice.call(arguments), Infinity) diff --git a/test/route.js b/test/route.js index f252343..1e560bb 100644 --- a/test/route.js +++ b/test/route.js @@ -1,6 +1,5 @@ const { it, describe } = require('mocha') const Buffer = require('safe-buffer').Buffer -const methods = require('methods') const series = require('run-series') const Router = require('..') const utils = require('./support/utils') @@ -13,6 +12,7 @@ const shouldHaveBody = utils.shouldHaveBody const shouldHitHandle = utils.shouldHitHandle const shouldNotHaveBody = utils.shouldNotHaveBody const shouldNotHitHandle = utils.shouldNotHitHandle +const methods = utils.methods const describePromises = global.Promise ? describe : describe.skip diff --git a/test/router.js b/test/router.js index 3c480d9..c3a9da8 100644 --- a/test/router.js +++ b/test/router.js @@ -1,7 +1,6 @@ const { it, describe } = require('mocha') const series = require('run-series') const Buffer = require('safe-buffer').Buffer -const methods = require('methods') const Router = require('..') const utils = require('./support/utils') @@ -14,6 +13,7 @@ const shouldHaveBody = utils.shouldHaveBody const shouldHitHandle = utils.shouldHitHandle const shouldNotHaveBody = utils.shouldNotHaveBody const shouldNotHitHandle = utils.shouldNotHitHandle +const methods = utils.methods const describePromises = global.Promise ? describe : describe.skip diff --git a/test/support/utils.js b/test/support/utils.js index 45ccb8a..c739355 100644 --- a/test/support/utils.js +++ b/test/support/utils.js @@ -2,9 +2,11 @@ const assert = require('assert') const Buffer = require('safe-buffer').Buffer const finalhandler = require('finalhandler') const http = require('http') -const methods = require('methods') +const { METHODS } = require('node:http') const request = require('supertest') +const methods = METHODS.map((method) => method.toLowerCase()) + exports.assert = assert exports.createHitHandle = createHitHandle exports.createServer = createServer @@ -14,6 +16,7 @@ exports.shouldHaveBody = shouldHaveBody exports.shouldNotHaveBody = shouldNotHaveBody exports.shouldHitHandle = shouldHitHandle exports.shouldNotHitHandle = shouldNotHitHandle +exports.methods = methods function createHitHandle (num) { const name = 'x-fn-' + String(num) From 0d2cefc7dc978cd34db6baad7d3a71ae2888eda3 Mon Sep 17 00:00:00 2001 From: Chris de Almeida Date: Thu, 24 Oct 2024 10:54:34 -0500 Subject: [PATCH 186/207] fix engines field for 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cbbba3b..706857f 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "index.js" ], "engines": { - "node": ">= 0.10" + "node": ">= 18" }, "scripts": { "lint": "standard", From 7a93a218906cbd1b00dcd293375abe6e0b35bc5c Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Mon, 11 Nov 2024 14:41:35 +0000 Subject: [PATCH 187/207] deps: parseurl@^1.3.3 (#133) --- HISTORY.md | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 5f69004..fd5f34c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ unreleased * Remove `Object.setPrototypeOf` polyfill * Use `Array.flat` instead of `array-flatten` package * Replace `methods` dependency with standard library +* deps: parseurl@^1.3.3 2.0.0 / 2024-09-09 ================== diff --git a/package.json b/package.json index 706857f..d7b4d66 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "repository": "pillarjs/router", "dependencies": { "is-promise": "4.0.0", - "parseurl": "~1.3.3", + "parseurl": "^1.3.3", "path-to-regexp": "^8.0.0", "utils-merge": "1.0.1" }, From 2a3af7ebe692cb686deddcd0e90ca5eca009635f Mon Sep 17 00:00:00 2001 From: Phillip9587 Date: Tue, 5 Nov 2024 11:38:19 +0100 Subject: [PATCH 188/207] ci: updated github actions ci workflow --- .github/workflows/ci.yml | 142 +++++++++++++-------------------------- 1 file changed, 45 insertions(+), 97 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96589d3..c39cc49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,126 +1,74 @@ name: ci - on: push: branches: - master - - '2.0' paths-ignore: - '*.md' pull_request: paths-ignore: - '*.md' +permissions: + contents: read + jobs: test: + name: Test - Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: - name: - - Node.js 18.x - - Node.js 19.x - - Node.js 20.x - - Node.js 21.x - - Node.js 22.x - - include: - - name: Node.js 18.x - node-version: "18" - - - name: Node.js 19.x - node-version: "19" - - - name: Node.js 20.x - node-version: "20" - - - name: Node.js 21.x - node-version: "21" - - - name: Node.js 22.x - node-version: "22" + node-version: [18, 19, 20, 21, 22, 23] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Install Node.js ${{ matrix.node-version }} - shell: bash -eo pipefail -l {0} - run: | - nvm install --default ${{ matrix.node-version }} - dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH" + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + check-latest: true - - name: Configure npm - run: | - if [[ "$(npm config get package-lock)" == "true" ]]; then - npm config set package-lock false - else - npm config set shrinkwrap false - fi + - name: Install Node.js dependencies + run: npm install - - name: Install Node.js dependencies - run: npm install + - name: Run tests + run: npm run test-ci - - name: List environment - id: list_env - shell: bash - run: | - echo "node@$(node -v)" - echo "npm@$(npm -v)" - npm -s ls ||: - (npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print $2 "=" $3 }' >> "$GITHUB_OUTPUT" + - name: Lint code + run: npm run lint - - name: Run tests - shell: bash - run: | - if npm -ps ls nyc | grep -q nyc; then - npm run test-ci - cp coverage/lcov.info "coverage/${{ matrix.name }}.lcov" - else - npm test - fi - - - name: Lint code - if: steps.list_env.outputs.eslint != '' - run: npm run lint - - - name: Collect code coverage - if: steps.list_env.outputs.nyc != '' - run: | - if [[ -d ./coverage ]]; then - mv ./coverage "./${{ matrix.name }}" - mkdir ./coverage - mv "./${{ matrix.name }}" "./coverage/${{ matrix.name }}" - fi - - name: Upload code coverage - uses: actions/upload-artifact@v3 - - if: steps.list_env.outputs.nyc != '' - with: - name: coverage - path: ./coverage - retention-days: 1 + - name: Upload code coverage + uses: actions/upload-artifact@v4 + with: + name: coverage-node-${{ matrix.node-version }} + path: ./coverage/lcov.info + retention-days: 1 coverage: needs: test runs-on: ubuntu-latest + permissions: + contents: read + checks: write steps: - - uses: actions/checkout@v3 - - - name: Install lcov - shell: bash - run: sudo apt-get -y install lcov - - - name: Collect coverage reports - uses: actions/download-artifact@v3 - with: - name: coverage - path: ./coverage - - - name: Merge coverage reports - shell: bash - run: find ./coverage -name lcov.info -exec printf '-a %q\n' {} \; | xargs lcov -o ./coverage/lcov.info - - - name: Upload coverage report - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v4 + + - name: Install lcov + shell: bash + run: sudo apt-get -y install lcov + + - name: Collect coverage reports + uses: actions/download-artifact@v4 + with: + path: ./coverage + pattern: coverage-node-* + + - name: Merge coverage reports + shell: bash + run: find ./coverage -name lcov.info -exec printf '-a %q\n' {} \; | xargs lcov -o ./lcov.info + + - name: Upload coverage report + uses: coverallsapp/github-action@v2 + with: + file: ./lcov.info From 8a7c46cec18dc8ce9a42f7c16c69d9a7fd3964d3 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Fri, 20 Dec 2024 18:42:51 +0100 Subject: [PATCH 189/207] chore: replace `utils-merge` dependency with `Object.assign()` (#138) --- HISTORY.md | 1 + index.js | 7 +++---- package.json | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index fd5f34c..cd9f75b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,7 @@ unreleased * Use `Array.flat` instead of `array-flatten` package * Replace `methods` dependency with standard library * deps: parseurl@^1.3.3 +* Replace `utils-merge` dependency with `Object.assign` 2.0.0 / 2024-09-09 ================== diff --git a/index.js b/index.js index aa0cbc0..f1a1ed5 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,6 @@ const isPromise = require('is-promise') const Layer = require('./lib/layer') const { METHODS } = require('node:http') -const mixin = require('utils-merge') const parseUrl = require('parseurl') const Route = require('./lib/route') @@ -527,11 +526,11 @@ function mergeParams (params, parent) { } // make copy of parent for base - const obj = mixin({}, parent) + const obj = Object.assign({}, parent) // simple non-numeric merging if (!(0 in params) || !(0 in parent)) { - return mixin(obj, params) + return Object.assign(obj, params) } let i = 0 @@ -557,7 +556,7 @@ function mergeParams (params, parent) { } } - return mixin(obj, params) + return Object.assign(obj, params) } /** diff --git a/package.json b/package.json index d7b4d66..60faba1 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,7 @@ "dependencies": { "is-promise": "4.0.0", "parseurl": "^1.3.3", - "path-to-regexp": "^8.0.0", - "utils-merge": "1.0.1" + "path-to-regexp": "^8.0.0" }, "devDependencies": { "after": "0.8.2", From e746be261625f8c84b5cb1355af13b41b3f18602 Mon Sep 17 00:00:00 2001 From: Brayan Duque <43283729+raiandexter0607@users.noreply.github.com> Date: Mon, 10 Feb 2025 13:17:10 -0500 Subject: [PATCH 190/207] fix(deps): ispromise@^4.0.0 (#135) --- HISTORY.md | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index cd9f75b..e139bf8 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,7 @@ unreleased * Use `Array.flat` instead of `array-flatten` package * Replace `methods` dependency with standard library * deps: parseurl@^1.3.3 +* deps: is-promise@^4.0.0 * Replace `utils-merge` dependency with `Object.assign` 2.0.0 / 2024-09-09 @@ -14,7 +15,7 @@ unreleased * deps: path-to-regexp@^8.0.0 - Drop support for partial capture group `router.route('/user(s?)/:user/:op')` but still have optional non-capture `/user{s}/:user/:op` - `:name?` becomes `{:name}` - - `:name*` becomes `*name`. + - `:name*` becomes `*name`. - The splat change also changes splat from strings to an array of strings - Optional splats become `{*name}` - `:name+` becomes `*name` and thus equivalent to `*name` so I dropped those tests diff --git a/package.json b/package.json index 60faba1..1687692 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "license": "MIT", "repository": "pillarjs/router", "dependencies": { - "is-promise": "4.0.0", + "is-promise": "^4.0.0", "parseurl": "^1.3.3", "path-to-regexp": "^8.0.0" }, From 4f1b458dae8a2f0486b8adbcfc971189e4a441dc Mon Sep 17 00:00:00 2001 From: Ulises Gascon Date: Tue, 29 Oct 2024 16:01:06 +0100 Subject: [PATCH 191/207] 2.1.0 Signed-off-by: Ulises Gascon --- HISTORY.md | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index e139bf8..b77e495 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,7 @@ -unreleased +2.1.0 / 2025-02-10 ================== +* Updated `engines` field to Node@18 or higher * Remove `Object.setPrototypeOf` polyfill * Use `Array.flat` instead of `array-flatten` package * Replace `methods` dependency with standard library diff --git a/package.json b/package.json index 1687692..7e19d9f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "router", "description": "Simple middleware-style router", - "version": "2.0.0", + "version": "2.1.0", "author": "Douglas Christopher Wilson ", "contributors": [ "Blake Embrey " From fd1dde87bcb5da9821d65d2473bbed6862efe180 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Mon, 3 Mar 2025 14:37:57 -0500 Subject: [PATCH 192/207] docs: remove security file (#152) --- SECURITY.md | 24 ------------------------ package.json | 1 - 2 files changed, 25 deletions(-) delete mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index d56acec..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,24 +0,0 @@ -# Security Policies and Procedures - -## Reporting a Bug - -The `router` team and community take all security bugs seriously. Thank you -for improving the security of the project. We appreciate your efforts and -responsible disclosure and will make every effort to acknowledge your -contributions. - -Report security bugs by emailing the current owner(s) of `router`. This information -can be found in the npm registry using the command `npm owner ls router`. -If unsure or unable to get the information from the above, open an issue -in the [project issue tracker](https://github.com/pillarjs/router/issues) -asking for the current contact information. - -To ensure the timely response to your report, please ensure that the entirety -of the report is contained within the email body and not solely behind a web -link or an attachment. - -At least one owner will acknowledge your email within 48 hours, and will send a -more detailed response within 48 hours indicating the next steps in handling -your report. After the initial reply to your report, the owners will -endeavor to keep you informed of the progress towards a fix and full -announcement, and may ask for additional information or guidance. diff --git a/package.json b/package.json index 7e19d9f..fc91fd3 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "LICENSE", "HISTORY.md", "README.md", - "SECURITY.md", "index.js" ], "engines": { From 79a8addf26be2e182f25ef6beabfea9b57bb18e1 Mon Sep 17 00:00:00 2001 From: Dustin Popp Date: Mon, 17 Feb 2025 17:18:51 -0600 Subject: [PATCH 193/207] fix: restore 'debug' logs Revert "Remove debug dependency", with the following changes: - Update "var" to "const" for debug imports - Preserve history file so intermediate versions are documented correctly - Use latest version of debug This reverts commit 0b5a0a6b578565cc36712f8d5004566bf5e1472f. --- HISTORY.md | 5 +++++ index.js | 8 ++++++++ lib/layer.js | 2 ++ lib/route.js | 4 ++++ package.json | 1 + 5 files changed, 20 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index b77e495..2ef6f8d 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +================== + +* Restore `debug` dependency + 2.1.0 / 2025-02-10 ================== diff --git a/index.js b/index.js index f1a1ed5..cff32c7 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,7 @@ const Layer = require('./lib/layer') const { METHODS } = require('node:http') const parseUrl = require('parseurl') const Route = require('./lib/route') +const debug = require('debug')('router') /** * Module variables. @@ -149,6 +150,8 @@ Router.prototype.handle = function handle (req, res, callback) { throw new TypeError('argument callback is required') } + debug('dispatching %s %s', req.method, req.url) + let idx = 0 let methods const protohost = getProtohost(req.url) || '' @@ -315,6 +318,7 @@ Router.prototype.handle = function handle (req, res, callback) { // Trim off the part of the url that matches the route // middleware (.use stuff) needs to have the path stripped + debug('trim prefix (%s) from url %s', layerPath, req.url) removed = layerPath req.url = protohost + req.url.slice(protohost.length + removed.length) @@ -330,6 +334,8 @@ Router.prototype.handle = function handle (req, res, callback) { : removed) } + debug('%s %s : %s', layer.name, layerPath, req.originalUrl) + if (layerError) { layer.handleError(layerError, req, res, next) } else { @@ -387,6 +393,8 @@ Router.prototype.use = function use (handler) { } // add the middleware + debug('use %o %s', path, fn.name || '') + const layer = new Layer(path, { sensitive: this.caseSensitive, strict: false, diff --git a/lib/layer.js b/lib/layer.js index e2fcba8..d228617 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -14,6 +14,7 @@ const isPromise = require('is-promise') const pathRegexp = require('path-to-regexp') +const debug = require('debug')('router:layer') /** * Module variables. @@ -34,6 +35,7 @@ function Layer (path, options, fn) { return new Layer(path, options, fn) } + debug('new %o', path) const opts = options || {} this.handle = fn diff --git a/lib/route.js b/lib/route.js index ec98414..cba2440 100644 --- a/lib/route.js +++ b/lib/route.js @@ -12,6 +12,7 @@ * @private */ +const debug = require('debug')('router:route') const Layer = require('./layer') const { METHODS } = require('node:http') @@ -43,6 +44,7 @@ module.exports = Route */ function Route (path) { + debug('new %o', path) this.path = path this.stack = [] @@ -231,6 +233,8 @@ methods.forEach(function (method) { throw new TypeError('argument handler must be a function') } + debug('%s %s', method, this.path) + const layer = Layer('/', {}, fn) layer.method = method diff --git a/package.json b/package.json index fc91fd3..41ac60e 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "license": "MIT", "repository": "pillarjs/router", "dependencies": { + "debug": "^4.4.0", "is-promise": "^4.0.0", "parseurl": "^1.3.3", "path-to-regexp": "^8.0.0" From a2623fa54ffaaeac3f04b0b83fd14bd35eca3622 Mon Sep 17 00:00:00 2001 From: Carlos Serrano Date: Wed, 5 Mar 2025 17:30:04 +0100 Subject: [PATCH 194/207] fix(ci): upgrade scorecard workflow pinned action versions (#150) --- .github/workflows/scorecard.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 3bfd85a..d23de00 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -3,6 +3,7 @@ # policy, and support documentation. name: Scorecard supply-chain security + on: # For Branch-Protection check. Only the default branch is supported. See # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection @@ -32,12 +33,12 @@ jobs: steps: - name: "Checkout code" - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: persist-credentials: false - name: "Run analysis" - uses: ossf/scorecard-action@99c53751e09b9529366343771cc321ec74e9bd3d # v2.0.6 + uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0 with: results_file: results.sarif results_format: sarif @@ -59,7 +60,7 @@ jobs: # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF # format to the repository Actions tab. - name: "Upload artifact" - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 + uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0 with: name: SARIF file path: results.sarif @@ -67,6 +68,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@2f93e4319b2f04a2efc38fa7f78bd681bc3f7b2f # v2.23.2 + uses: github/codeql-action/upload-sarif@df409f7d9260372bd5f19e5b04e83cb3c43714ae # v3.27.9 with: sarif_file: results.sarif \ No newline at end of file From 08b6a3266a641a70323438e4ec34ce1f9bd39177 Mon Sep 17 00:00:00 2001 From: Phillip9587 Date: Tue, 5 Nov 2024 11:57:11 +0100 Subject: [PATCH 195/207] fix(deps): remove unused devDependency `after` --- HISTORY.md | 1 + package.json | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 2ef6f8d..24eaf3a 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -13,6 +13,7 @@ unreleased * deps: parseurl@^1.3.3 * deps: is-promise@^4.0.0 * Replace `utils-merge` dependency with `Object.assign` +* deps: Remove unused dep `after` 2.0.0 / 2024-09-09 ================== diff --git a/package.json b/package.json index 41ac60e..14dd49e 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "path-to-regexp": "^8.0.0" }, "devDependencies": { - "after": "0.8.2", "finalhandler": "1.2.0", "mocha": "10.2.0", "nyc": "15.1.0", From 337c45b57d66280a8b77667f6299b446dabc86a5 Mon Sep 17 00:00:00 2001 From: Phillip Barta Date: Wed, 5 Mar 2025 17:46:30 +0100 Subject: [PATCH 196/207] fix: remove `setImmediate` support check (#144) setImmediate is available since Node.js v0.9.1 Co-authored-by: Wes Todd --- HISTORY.md | 1 + lib/route.js | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 24eaf3a..62b9750 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,7 @@ unreleased ================== +* Remove `setImmediate` support check * Restore `debug` dependency 2.1.0 / 2025-02-10 diff --git a/lib/route.js b/lib/route.js index cba2440..1887d78 100644 --- a/lib/route.js +++ b/lib/route.js @@ -25,11 +25,6 @@ const slice = Array.prototype.slice const flatten = Array.prototype.flat const methods = METHODS.map((method) => method.toLowerCase()) -/* istanbul ignore next */ -const defer = typeof setImmediate === 'function' - ? setImmediate - : function (fn) { process.nextTick(fn.bind.apply(fn, arguments)) } - /** * Expose `Route`. */ @@ -139,7 +134,7 @@ Route.prototype.dispatch = function dispatch (req, res, done) { // max sync stack if (++sync > 100) { - return defer(next, err) + return setImmediate(next, err) } let layer From c10d69e8214ebb4b92922c37a504b5308b1692b1 Mon Sep 17 00:00:00 2001 From: Phillip Barta Date: Wed, 5 Mar 2025 17:47:14 +0100 Subject: [PATCH 197/207] fix: remove promise support check from tests (#141) Promises are supported in all supported Node.js version so the check is unnecessary --- test/param.js | 4 +--- test/route.js | 4 +--- test/router.js | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/test/param.js b/test/param.js index 52fd006..fe7019d 100644 --- a/test/param.js +++ b/test/param.js @@ -10,8 +10,6 @@ const shouldNotHitHandle = utils.shouldNotHitHandle const createServer = utils.createServer const request = utils.request -const describePromises = global.Promise ? describe : describe.skip - describe('Router', function () { describe('.param(name, fn)', function () { it('should reject missing name', function () { @@ -264,7 +262,7 @@ describe('Router', function () { .expect(500, /Error: boom/, done) }) - describePromises('promise support', function () { + describe('promise support', function () { it('should pass rejected promise value', function (done) { const router = new Router() const server = createServer(router) diff --git a/test/route.js b/test/route.js index 1e560bb..d93471b 100644 --- a/test/route.js +++ b/test/route.js @@ -14,8 +14,6 @@ const shouldNotHaveBody = utils.shouldNotHaveBody const shouldNotHitHandle = utils.shouldNotHitHandle const methods = utils.methods -const describePromises = global.Promise ? describe : describe.skip - describe('Router', function () { describe('.route(path)', function () { it('should return a new route', function () { @@ -542,7 +540,7 @@ describe('Router', function () { }) }) - describePromises('promise support', function () { + describe('promise support', function () { it('should pass rejected promise value', function (done) { const router = new Router() const route = router.route('/foo') diff --git a/test/router.js b/test/router.js index c3a9da8..2dd41c5 100644 --- a/test/router.js +++ b/test/router.js @@ -15,8 +15,6 @@ const shouldNotHaveBody = utils.shouldNotHaveBody const shouldNotHitHandle = utils.shouldNotHitHandle const methods = utils.methods -const describePromises = global.Promise ? describe : describe.skip - describe('Router', function () { it('should return a function', function () { assert.equal(typeof Router(), 'function') @@ -770,7 +768,7 @@ describe('Router', function () { }) }) - describePromises('promise support', function () { + describe('promise support', function () { it('should pass rejected promise value', function (done) { const router = new Router() const server = createServer(router) From 21debd95b59e2bbae696950f286d697cc618694d Mon Sep 17 00:00:00 2001 From: Phillip Barta Date: Wed, 5 Mar 2025 17:48:57 +0100 Subject: [PATCH 198/207] fix: remove devDependency `safe-buffer` (#140) --- package.json | 1 - test/route.js | 1 - test/router.js | 1 - test/support/utils.js | 1 - 4 files changed, 4 deletions(-) diff --git a/package.json b/package.json index 14dd49e..d819cd3 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "mocha": "10.2.0", "nyc": "15.1.0", "run-series": "^1.1.9", - "safe-buffer": "5.2.1", "standard": "^17.1.0", "supertest": "6.3.3" }, diff --git a/test/route.js b/test/route.js index d93471b..dd51298 100644 --- a/test/route.js +++ b/test/route.js @@ -1,5 +1,4 @@ const { it, describe } = require('mocha') -const Buffer = require('safe-buffer').Buffer const series = require('run-series') const Router = require('..') const utils = require('./support/utils') diff --git a/test/router.js b/test/router.js index 2dd41c5..b440e40 100644 --- a/test/router.js +++ b/test/router.js @@ -1,6 +1,5 @@ const { it, describe } = require('mocha') const series = require('run-series') -const Buffer = require('safe-buffer').Buffer const Router = require('..') const utils = require('./support/utils') diff --git a/test/support/utils.js b/test/support/utils.js index c739355..2fab2fb 100644 --- a/test/support/utils.js +++ b/test/support/utils.js @@ -1,5 +1,4 @@ const assert = require('assert') -const Buffer = require('safe-buffer').Buffer const finalhandler = require('finalhandler') const http = require('http') const { METHODS } = require('node:http') From 276d40d033228e411eb34f1d557669c11fea3d00 Mon Sep 17 00:00:00 2001 From: Rakesh Bisht Date: Wed, 5 Mar 2025 22:35:26 +0530 Subject: [PATCH 199/207] fix: 'continue' is unnecessary as the last statement in while loop inside next() method (#107) --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index cff32c7..5c5caa2 100644 --- a/index.js +++ b/index.js @@ -267,7 +267,6 @@ Router.prototype.handle = function handle (req, res, callback) { // don't even bother matching route if (!hasMethod && method !== 'HEAD') { match = false - continue } } From 79beed136092718fe6534fa6381a62003810f7ab Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Mon, 24 Mar 2025 00:32:49 +0100 Subject: [PATCH 200/207] chore: upgrade `finalhandler` to 2.1.0 (#153) Signed-off-by: Jon Koops --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d819cd3..3c79e0d 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "path-to-regexp": "^8.0.0" }, "devDependencies": { - "finalhandler": "1.2.0", + "finalhandler": "^2.1.0", "mocha": "10.2.0", "nyc": "15.1.0", "run-series": "^1.1.9", From 2226ece8fd033276c9e9530d8d4fde706f900018 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Mon, 24 Mar 2025 12:06:47 +0100 Subject: [PATCH 201/207] feat: deprecate non-native Promises (#154) Signed-off-by: Jon Koops --- index.js | 5 +++++ lib/layer.js | 9 +++++++++ package.json | 1 + 3 files changed, 15 insertions(+) diff --git a/index.js b/index.js index 5c5caa2..4358aeb 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ const { METHODS } = require('node:http') const parseUrl = require('parseurl') const Route = require('./lib/route') const debug = require('debug')('router') +const deprecate = require('depd')('router') /** * Module variables. @@ -647,6 +648,10 @@ function processParams (params, layer, called, req, res, done) { try { const ret = fn(req, res, paramCallback, paramVal, key) if (isPromise(ret)) { + if (!(ret instanceof Promise)) { + deprecate('parameters that are Promise-like are deprecated, use a native Promise instead') + } + ret.then(null, function (error) { paramCallback(error || new Error('Rejected promise')) }) diff --git a/lib/layer.js b/lib/layer.js index d228617..6a4408f 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -15,6 +15,7 @@ const isPromise = require('is-promise') const pathRegexp = require('path-to-regexp') const debug = require('debug')('router:layer') +const deprecate = require('depd')('router') /** * Module variables. @@ -116,6 +117,10 @@ Layer.prototype.handleError = function handleError (error, req, res, next) { // wait for returned promise if (isPromise(ret)) { + if (!(ret instanceof Promise)) { + deprecate('handlers that are Promise-like are deprecated, use a native Promise instead') + } + ret.then(null, function (error) { next(error || new Error('Rejected promise')) }) @@ -148,6 +153,10 @@ Layer.prototype.handleRequest = function handleRequest (req, res, next) { // wait for returned promise if (isPromise(ret)) { + if (!(ret instanceof Promise)) { + deprecate('handlers that are Promise-like are deprecated, use a native Promise instead') + } + ret.then(null, function (error) { next(error || new Error('Rejected promise')) }) diff --git a/package.json b/package.json index 3c79e0d..41fc9b4 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "repository": "pillarjs/router", "dependencies": { "debug": "^4.4.0", + "depd": "^2.0.0", "is-promise": "^4.0.0", "parseurl": "^1.3.3", "path-to-regexp": "^8.0.0" From e6d6b609fc355e558174ccd5b1db646f739fe88c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulises=20Gasc=C3=B3n?= Date: Thu, 27 Mar 2025 01:33:54 +0100 Subject: [PATCH 202/207] 2.2.0 (#157) --- HISTORY.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 62b9750..b292257 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,4 +1,4 @@ -unreleased +2.2.0 / 2025-03-26 ================== * Remove `setImmediate` support check diff --git a/package.json b/package.json index 41fc9b4..123eca2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "router", "description": "Simple middleware-style router", - "version": "2.1.0", + "version": "2.2.0", "author": "Douglas Christopher Wilson ", "contributors": [ "Blake Embrey " From 19f241bca8789a684d694e95711ddd1e6b83d8a4 Mon Sep 17 00:00:00 2001 From: StepSecurity Bot Date: Mon, 2 Jun 2025 03:56:24 -0700 Subject: [PATCH 203/207] ci: apply security best practices (#161) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ulises Gascón --- .github/dependabot.yml | 17 +++++++++ .github/workflows/ci.yml | 12 +++--- .github/workflows/codeql.yml | 73 ++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/codeql.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..17c705f --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,17 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: monthly + + - package-ecosystem: npm + directory: / + schedule: + interval: monthly + time: "23:00" + timezone: Europe/London + open-pull-requests-limit: 10 + ignore: + - dependency-name: "*" + update-types: ["version-update:semver-major"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c39cc49..8a4ce9e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,9 +22,9 @@ jobs: node-version: [18, 19, 20, 21, 22, 23] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/setup-node@v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: node-version: ${{ matrix.node-version }} check-latest: true @@ -39,7 +39,7 @@ jobs: run: npm run lint - name: Upload code coverage - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: coverage-node-${{ matrix.node-version }} path: ./coverage/lcov.info @@ -52,14 +52,14 @@ jobs: contents: read checks: write steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Install lcov shell: bash run: sudo apt-get -y install lcov - name: Collect coverage reports - uses: actions/download-artifact@v4 + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: path: ./coverage pattern: coverage-node-* @@ -69,6 +69,6 @@ jobs: run: find ./coverage -name lcov.info -exec printf '-a %q\n' {} \; | xargs lcov -o ./lcov.info - name: Upload coverage report - uses: coverallsapp/github-action@v2 + uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6 with: file: ./lcov.info diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..cc15ef7 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,73 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: ["master"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["master"] + schedule: + - cron: "0 0 * * 1" + +permissions: + contents: read + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ["javascript"] + # CodeQL supports [ $supported-codeql-languages ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 + with: + category: "/language:${{matrix.language}}" From 18e8245635d30aabdcb5af07cf04a577b386bb8f Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Wed, 23 Jul 2025 07:38:53 -0500 Subject: [PATCH 204/207] chore: add funding to package.json (#172) --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index 123eca2..e465e6c 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,10 @@ ], "license": "MIT", "repository": "pillarjs/router", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + }, "dependencies": { "debug": "^4.4.0", "depd": "^2.0.0", From 3d574ed80df980eec937bd0c842e8cbf3fbf45a6 Mon Sep 17 00:00:00 2001 From: TripleChecker <197429080+triplechecker-com@users.noreply.github.com> Date: Thu, 24 Jul 2025 13:58:17 +0300 Subject: [PATCH 205/207] doc: correct typos and improve readability (#173) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 218fd57..156c380 100644 --- a/README.md +++ b/README.md @@ -316,7 +316,7 @@ var finalhandler = require('finalhandler') // this example is about the mergeParams option var opts = { mergeParams: true } -// make a router with out special options +// make a router with our special options var router = Router(opts) var server = http.createServer(function onRequest (req, res) { // set something to be passed into the router @@ -329,7 +329,7 @@ router.get('/', function (req, res) { res.statusCode = 200 res.setHeader('Content-Type', 'text/plain; charset=utf-8') - // with respond with the the params that were passed in + // with respond with the params that were passed in res.end(req.params.type + '\n') }) From 268b62ba9c331352866ea21be3548d1bebc96d70 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Tue, 29 Jul 2025 06:11:53 -0500 Subject: [PATCH 206/207] ci: add node 24 (#175) --- .github/workflows/ci.yml | 8 +++----- package.json | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a4ce9e..ef911a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,11 +3,9 @@ on: push: branches: - master - paths-ignore: - - '*.md' pull_request: - paths-ignore: - - '*.md' + branches: + - master permissions: contents: read @@ -19,7 +17,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [18, 19, 20, 21, 22, 23] + node-version: [18, 19, 20, 21, 22, 23, 24] steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 diff --git a/package.json b/package.json index e465e6c..e6be557 100644 --- a/package.json +++ b/package.json @@ -39,8 +39,8 @@ }, "scripts": { "lint": "standard", - "test": "mocha --reporter spec --bail --check-leaks test/", - "test:debug": "mocha --reporter spec --bail --check-leaks test/ --inspect --inspect-brk", + "test": "mocha --reporter spec --check-leaks test/", + "test:debug": "mocha --reporter spec --check-leaks test/ --inspect --inspect-brk", "test-ci": "nyc --reporter=lcov --reporter=text npm test", "test-cov": "nyc --reporter=text npm test", "version": "node scripts/version-history.js && git add HISTORY.md" From cb2a5fcdf31b9cc92296183ceeff8126b5c57453 Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Fri, 15 Aug 2025 09:02:24 -0500 Subject: [PATCH 207/207] feat(test): allow dispatch trigger on ci test workflow (#177) --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef911a3..dffb14f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,7 @@ name: ci on: + workflow_call: + workflow_dispatch: push: branches: - master