From 4aae4fb614591cded27e0f04bb4df87d8321dfd0 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Thu, 5 Jul 2018 20:02:05 +0200 Subject: [PATCH] add a slash if the prefix is equal to the url --- index.js | 2 +- test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index eb0793e..dff0403 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,6 @@ module.exports = async function (fastify, opts) { function reply (request, reply) { var dest = request.req.url.replace(this.basePath, '') - reply.from(dest) + reply.from(dest || '/') } } diff --git a/test.js b/test.js index 245f786..211a59e 100644 --- a/test.js +++ b/test.js @@ -68,6 +68,9 @@ async function run () { const resultRoot = await got(`http://localhost:${server.server.address().port}/my-prefix/`) t.equal(resultRoot.body, 'this is root') + const withoutSlash = await got(`http://localhost:${server.server.address().port}/my-prefix`) + t.equal(withoutSlash.body, 'this is root') + const resultA = await got(`http://localhost:${server.server.address().port}/my-prefix/a`) t.equal(resultA.body, 'this is a') })