Repository navigation
fix: add opt-in appendAutoPrefix for directory auto prefixes - #498
Merged
jean-michelet merged 6 commits intoJul 24, 2026
Merged
Conversation
mcollina
requested changes
Mar 11, 2026
Contributor
Author
|
Thanks for the review — I pushed an update to clarify the behavior and example in README. What changed:
Validation:
If you want, I can also add a short one-line cross-reference from |
Tony133
approved these changes
Jul 16, 2026
Member
|
@SergioChan as soon as you have time, could you resolve the two issues that were flagged? The one regarding the tests is the priority, at the very least. |
Signed-off-by: Yuheng <cyh9211@icloud.com>
Contributor
Author
|
@Tony133 resolved both flagged threads.
Validation:
Both review threads are now resolved. |
Member
Thanks! |
Member
|
@SergioChan one last change: can you update the test so we remove the try/finally block in favor of 'use strict'
const { describe, it } = require('node:test')
const assert = require('node:assert')
const path = require('node:path')
const Fastify = require('fastify')
const autoLoad = require('../../../')
describe('Issue 205: append autoPrefix to directory prefixes without breaking defaults', function () {
it('should keep autoPrefix overriding directory prefixes by default', async function (t) {
const app = Fastify()
t.after(() => app.close())
app.register(autoLoad, {
dir: path.join(__dirname, 'routes'),
options: { prefix: '/hooked-plugin' }
})
await app.ready()
const overridden = await app.inject({ method: 'GET', url: '/hooked-plugin/batch/entity' })
assert.strictEqual(overridden.statusCode, 200)
assert.deepStrictEqual(overridden.json(), { ok: true })
const appended = await app.inject({ method: 'GET', url: '/hooked-plugin/children/batch/entity' })
assert.strictEqual(appended.statusCode, 404)
})
it('should concatenate directory prefixes before plugin autoPrefix when appendAutoPrefix is true', async function (t) {
const app = Fastify()
t.after(() => app.close())
app.register(autoLoad, {
dir: path.join(__dirname, 'routes'),
options: { prefix: '/hooked-plugin' },
appendAutoPrefix: true
})
await app.ready()
const appended = await app.inject({ method: 'GET', url: '/hooked-plugin/children/batch/entity' })
assert.strictEqual(appended.statusCode, 200)
assert.deepStrictEqual(appended.json(), { ok: true })
const overridden = await app.inject({ method: 'GET', url: '/hooked-plugin/batch/entity' })
assert.strictEqual(overridden.statusCode, 404)
})
}) |
Signed-off-by: Yuheng <cyh9211@icloud.com>
Contributor
Author
Tony133
approved these changes
Jul 16, 2026
jean-michelet
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
appendAutoPrefixautoload option (defaultfalse)plugin.autoPrefixstill overrides directory-derived prefixes)appendAutoPrefix: true, concatenate directory prefix +plugin.autoPrefixIssue
Closes #205 and close this PR #350
Validation
node --test test/issues/205/test.jsnode --test test/commonjs/basic.js