Comparing version 3.2.0 to 3.2.1
@@ -103,3 +103,6 @@ 'use strict' | ||
if (result) { | ||
req.url = req.url.replace(result[0], '/') | ||
req.url = req.url.replace(result[0], '') | ||
if (req.url.startsWith('/') === false) { | ||
req.url = '/' + req.url | ||
} | ||
fn(req, res, that.done) | ||
@@ -106,0 +109,0 @@ } else { |
{ | ||
"name": "middie", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Middleware engine for Fastify", | ||
@@ -5,0 +5,0 @@ "main": "middie.js", |
71
test.js
@@ -94,3 +94,3 @@ 'use strict' | ||
test('run restricted by path', t => { | ||
t.plan(9) | ||
t.plan(11) | ||
@@ -118,2 +118,7 @@ const instance = middie(function (err, a, b) { | ||
t.equal(instance.use('/test', function (req, res, next) { | ||
t.equal('/', req.url) | ||
next() | ||
}), instance) | ||
t.equal(instance.use('/no-call', function (req, res, next) { | ||
@@ -127,2 +132,66 @@ t.fail('should not call this function') | ||
test('run restricted by path - prefix override', t => { | ||
t.plan(10) | ||
const instance = middie(function (err, a, b) { | ||
t.error(err) | ||
t.equal(a, req) | ||
t.equal('/test/other/one', req.url) | ||
t.equal(b, res) | ||
}) | ||
const req = { | ||
url: '/test/other/one' | ||
} | ||
const res = {} | ||
t.equal(instance.use(function (req, res, next) { | ||
t.ok('function called') | ||
next() | ||
}), instance) | ||
t.equal(instance.use('/test', function (req, res, next) { | ||
t.ok('function called') | ||
next() | ||
}), instance) | ||
t.equal(instance.use('/test', function (req, res, next) { | ||
t.equal('/other/one', req.url) | ||
next() | ||
}), instance) | ||
instance.run(req, res) | ||
}) | ||
test('run restricted by path - prefix override 2', t => { | ||
t.plan(10) | ||
const instance = middie(function (err, a, b) { | ||
t.error(err) | ||
t.equal(a, req) | ||
t.equal('/tasks-api/task', req.url) | ||
t.equal(b, res) | ||
}) | ||
const req = { | ||
url: '/tasks-api/task' | ||
} | ||
const res = {} | ||
t.equal(instance.use(function (req, res, next) { | ||
t.ok('function called') | ||
next() | ||
}), instance) | ||
t.equal(instance.use('/tasks-api', function (req, res, next) { | ||
t.ok('function called') | ||
next() | ||
}), instance) | ||
t.equal(instance.use('/tasks-api', function (req, res, next) { | ||
t.equal('/task', req.url) | ||
next() | ||
}), instance) | ||
instance.run(req, res) | ||
}) | ||
test('run restricted by array path', t => { | ||
@@ -129,0 +198,0 @@ t.plan(9) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17982
535