Skip to content

Commit

Permalink
Merge e90b83e into d2b2099
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jan 8, 2019
2 parents d2b2099 + e90b83e commit 4b0932b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions index.js
Expand Up @@ -329,6 +329,11 @@ Router.prototype.find = function find (method, path, version) {
if (this.caseSensitive === false) {
path = path.toLowerCase()
}

if (path.charCodeAt(0) !== 47) { // 47 is '/'
path = path.replace(/^https?:\/\/.*\//, '/')
}

var maxParamLength = this.maxParamLength
var currentNode = this.tree
var wildcardNode = null
Expand Down
3 changes: 0 additions & 3 deletions test/case-insesitive.test.js
Expand Up @@ -100,7 +100,6 @@ test('case insensitive with capital letter in static path with param', t => {
})

findMyWay.on('GET', '/Foo/bar/:param', (req, res, params) => {
console.log('baz')
t.equal(params.param, 'baz')
})

Expand All @@ -122,12 +121,10 @@ test('case insensitive with multiple paths containing capital letter in static p
})

findMyWay.on('GET', '/Foo/bar/:param', (req, res, params) => {
console.log('baz')
t.equal(params.param, 'baz')
})

findMyWay.on('GET', '/Foo/baz/:param', (req, res, params) => {
console.log('bar')
t.equal(params.param, 'bar')
})

Expand Down
19 changes: 19 additions & 0 deletions test/full-url.test.js
@@ -0,0 +1,19 @@
'use strict'

const t = require('tap')
const FindMyWay = require('../')

const findMyWay = FindMyWay({
defaultRoute: (req, res) => {
t.fail('Should not be defaultRoute')
}
})

findMyWay.on('GET', '/a', (req, res) => {
res.end('{"message":"hello world"}')
})

t.deepEqual(findMyWay.find('GET', 'http://localhost/a'), findMyWay.find('GET', '/a'))
t.deepEqual(findMyWay.find('GET', 'http://localhost:8080/a'), findMyWay.find('GET', '/a'))
t.deepEqual(findMyWay.find('GET', 'http://123.123.123.123/a'), findMyWay.find('GET', '/a'))
t.deepEqual(findMyWay.find('GET', 'https://localhost/a'), findMyWay.find('GET', '/a'))

0 comments on commit 4b0932b

Please sign in to comment.