Skip to content

Commit

Permalink
Merge branch 'master' into 2.0-v1-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleytodd committed Mar 16, 2024
2 parents c67be54 + 86a5f76 commit 1a5eb08
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
33 changes: 22 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
- Node.js 16.x
- Node.js 17.x
- Node.js 18.x
- Node.js 19.x

include:
- name: Node.js 0.10
Expand Down Expand Up @@ -86,27 +87,32 @@ 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"

- name: Node.js 16.x
node-version: "16.15"
node-version: "16.19"

- name: Node.js 17.x
node-version: "17.9"

- name: Node.js 18.x
node-version: "18.0"
node-version: "18.14"

- name: Node.js 19.x
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}
Expand All @@ -115,7 +121,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 }}
Expand All @@ -125,8 +136,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 | \
Expand All @@ -143,7 +154,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
Expand All @@ -168,7 +179,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:
Expand All @@ -180,14 +191,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
Expand Down
7 changes: 6 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -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`

Expand Down Expand Up @@ -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
==================

Expand Down
11 changes: 8 additions & 3 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -104,8 +106,11 @@ Route.prototype.dispatch = function dispatch (req, res, done) {
return done()
}

var method = req.method.toLowerCase()
if (method === 'head' && !this.methods.head) {
var method = typeof req.method === 'string'
? req.method.toLowerCase()
: req.method

if (method === 'head' && !this.methods['head']) {
method = 'get'
}

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
24 changes: 24 additions & 0 deletions test/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1a5eb08

Please sign in to comment.