Skip to content

Commit

Permalink
Revert "fix: autohooks prefix concatenation (#378)"
Browse files Browse the repository at this point in the history
This reverts commit d508f82.
  • Loading branch information
climba03003 authored and jean-michelet committed Jun 17, 2024
1 parent 24e352a commit 1833842
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 88 deletions.
7 changes: 1 addition & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ const fastifyAutoload = async function autoload (fastify, options) {
const pluginArray = [].concat.apply([], Object.values(pluginTree).map(o => o.plugins))
const hookArray = [].concat.apply([], Object.values(pluginTree).map(o => o.hooks))

let rootPrefix = options.options?.prefix ?? ''
// when prefix is provided /prefix/ format
// it is not good for concat, since most folder prefix start with /
if (rootPrefix[rootPrefix.length - 1] === '/') rootPrefix = rootPrefix.slice(0, -1)

await Promise.all(pluginArray.map(({ file, type, prefix }) => {
return loadPlugin({ file, type, directoryPrefix: prefix, options: opts, log: fastify.log })
.then((plugin) => {
Expand Down Expand Up @@ -90,7 +85,7 @@ const fastifyAutoload = async function autoload (fastify, options) {
}

fastify.register(composedPlugin, {
prefix: rootPrefix + replaceRouteParamPattern(prefix)
prefix: options.options?.prefix ?? replaceRouteParamPattern(prefix)
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/issues/326/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ app.ready(function (err) {
})

app.inject({
url: '/custom-prefix/child'
url: '/custom-prefix'
}, function (err, res) {
t.error(err)

t.equal(res.statusCode, 200)
})

app.inject({
url: '/custom-prefix/child/not-exists'
url: '/custom-prefix/not-exists'
}, function (err, res) {
t.error(err)
t.equal(res.headers.from, 'routes-b')
Expand Down
8 changes: 0 additions & 8 deletions test/issues/376/routes/entity/.autohooks.js

This file was deleted.

7 changes: 0 additions & 7 deletions test/issues/376/routes/entity/index.js

This file was deleted.

7 changes: 0 additions & 7 deletions test/issues/376/routes/index.js

This file was deleted.

58 changes: 0 additions & 58 deletions test/issues/376/test.js

This file was deleted.

0 comments on commit 1833842

Please sign in to comment.