Skip to content

Commit ae622e7

Browse files
authored
Merge pull request #9 from fastify/add-slash
add a slash if the prefix is equal to the url
2 parents 4d9c3a7 + 4aae4fb commit ae622e7

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ module.exports = async function (fastify, opts) {
2626

2727
function reply (request, reply) {
2828
var dest = request.req.url.replace(this.basePath, '')
29-
reply.from(dest)
29+
reply.from(dest || '/')
3030
}
3131
}

test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ async function run () {
6868
const resultRoot = await got(`http://localhost:${server.server.address().port}/my-prefix/`)
6969
t.equal(resultRoot.body, 'this is root')
7070

71+
const withoutSlash = await got(`http://localhost:${server.server.address().port}/my-prefix`)
72+
t.equal(withoutSlash.body, 'this is root')
73+
7174
const resultA = await got(`http://localhost:${server.server.address().port}/my-prefix/a`)
7275
t.equal(resultA.body, 'this is a')
7376
})

0 commit comments

Comments
 (0)