Skip to content

Commit

Permalink
docs(readme): autoPrefix behaviour with dirname prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
KcZer0 committed Dec 28, 2023
1 parent 30c592c commit 2db2d19
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Autoload can be customised using the following options:

module.exports.autoPrefix = '/something'


// /plugins/something.mjs
export default function (f, opts, next) {
f.get('/', (request, reply) => {
Expand All @@ -203,11 +204,35 @@ Autoload can be customised using the following options:
next()
}

export const autoPrefix = '/prefixed'
export const autoPrefix = '/something'

// routes can now be added to /defaultPrefix/something
```
When `options.dirNameRoutePrefix` is also set, `autoPrefix` will be concatenated *after* the directory prefix.
```js
// /plugins/someDir/something.js
module.exports = function (fastify, opts, next) {
// your plugin
}
module.exports.autoPrefix = '/prefixed'


// /plugins/someDir/something.mjs
export default function (f, opts, next) {
f.get('/', (request, reply) => {
reply.send({ something: 'else' })
})

next()
}

export const autoPrefix = '/prefixed'

// routes are now added to /defaultPrefix/someDir/prefixed
```
- `autoHooks` (optional) - Apply hooks from `autohooks.js` file(s) to plugins found in folder
Automatic hooks from `autohooks` files will be encapsulated with plugins. If `false`, all `autohooks.js` files will be ignored.
Expand Down Expand Up @@ -357,7 +382,7 @@ Each plugin can be individually configured using the following module properties
})
}

export const autoPrefix = '/prefixed'
export const autoPrefix = '/something'
```
Expand Down

0 comments on commit 2db2d19

Please sign in to comment.