diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f58d69f..18be98d 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.10 @@ -30,6 +35,7 @@ jobs: - Node.js 16.x - Node.js 17.x - Node.js 18.x + - Node.js 19.x include: - name: Node.js 0.10 @@ -70,11 +76,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" @@ -86,27 +92,37 @@ 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.19" + node-version: "14.21" - name: Node.js 15.x node-version: "15.14" + legacy-peer-deps: true - name: Node.js 16.x - node-version: "16.15" + 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.0" + 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@v2 + - uses: actions/checkout@v3 - name: Install Node.js ${{ matrix.node-version }} shell: bash -eo pipefail -l {0} @@ -115,7 +131,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: Install npm module(s) ${{ matrix.npm-i }} run: npm install --save-dev ${{ matrix.npm-i }} @@ -125,8 +146,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 | \ @@ -134,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 @@ -143,7 +164,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 @@ -168,7 +189,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: @@ -180,14 +201,14 @@ jobs: needs: test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install lcov shell: bash 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 diff --git a/HISTORY.md b/HISTORY.md index 1e1e91c..246fc47 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,7 +1,7 @@ 2.x === -This incorporates all changes after 1.3.5 up to 1.3.7. +This incorporates all changes after 1.3.5 up to 1.3.8. * Add support for returned, rejected Promises to `router.param` @@ -42,6 +42,11 @@ This incorporates all changes after 1.3.3 up to 1.3.5. - Remove `DEBUG_FD` environment variable support - Support 256 namespace colors +1.3.8 / 2023-02-24 +================== + + * Fix routing requests without method + 1.3.7 / 2022-04-28 ================== diff --git a/lib/route.js b/lib/route.js index 5098cb4..2a17763 100644 --- a/lib/route.js +++ b/lib/route.js @@ -59,7 +59,9 @@ Route.prototype._handlesMethod = function _handlesMethod (method) { } // normalize name - var name = method.toLowerCase() + var name = typeof method === 'string' + ? method.toLowerCase() + : method if (name === 'head' && !this.methods.head) { name = 'get' @@ -104,7 +106,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/package.json b/package.json index b18ef68..63d1f8b 100644 --- a/package.json +++ b/package.json @@ -19,18 +19,18 @@ }, "devDependencies": { "after": "0.8.2", - "eslint": "7.32.0", + "eslint": "8.34.0", "eslint-config-standard": "14.1.1", "eslint-plugin-import": "2.26.0", - "eslint-plugin-markdown": "2.2.1", + "eslint-plugin-markdown": "3.0.0", "eslint-plugin-node": "11.1.0", "eslint-plugin-promise": "5.2.0", "eslint-plugin-standard": "4.1.0", "finalhandler": "1.2.0", - "mocha": "9.2.2", + "mocha": "10.2.0", "nyc": "15.1.0", "safe-buffer": "5.2.1", - "supertest": "6.2.3" + "supertest": "6.3.3" }, "files": [ "lib/", diff --git a/test/route.js b/test/route.js index 5bfe75b..fcd6f8b 100644 --- a/test/route.js +++ b/test/route.js @@ -46,6 +46,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()