-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow
autoConfig
with callback (#381)
* feat: handle autoConfig callbacks * docs: document new option type * test: test prefix behavior documented in doc * fix: merge pluginConfig callback result with overrideConfig * fix: prioritize overridden prefix
- Loading branch information
1 parent
930e738
commit a802a8f
Showing
12 changed files
with
171 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
module.exports = function (f, opts, next) { | ||
f.get('/', (request, reply) => { | ||
reply.send({ configPrefix: true }) | ||
}) | ||
|
||
next() | ||
} | ||
|
||
module.exports.autoConfig = { | ||
prefix: '/configPrefix' | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
module.exports = function (f, opts, next) { | ||
f.get('/', (request, reply) => { | ||
reply.send({ configPrefixCallback: true }) | ||
}) | ||
|
||
next() | ||
} | ||
|
||
const options = () => ({}) | ||
options.prefix = '/configPrefixCallback' | ||
|
||
module.exports.autoConfig = options |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict' | ||
|
||
const fp = require('fastify-plugin') | ||
|
||
function plugin (f, opts, next) { | ||
f.get('/plugin-e', (request, reply) => { | ||
reply.send({ data: opts.e }) | ||
}) | ||
|
||
next() | ||
} | ||
|
||
plugin.autoConfig = (fastify) => { | ||
return { e: 'test-4-' + fastify.root } | ||
} | ||
|
||
exports.default = fp(plugin, { name: 'plugin-e' }) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
export default function (f, opts, next) { | ||
f.get('/', (request, reply) => { | ||
reply.send({ configPrefix: true }) | ||
}) | ||
|
||
next() | ||
} | ||
|
||
export const autoConfig = { | ||
prefix: '/configPrefix' | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict' | ||
|
||
export default function (f, opts, next) { | ||
f.get('/', (request, reply) => { | ||
reply.send({ configPrefixCallback: true }) | ||
}) | ||
|
||
next() | ||
} | ||
|
||
export const autoConfig = () => ({}) | ||
autoConfig.prefix = '/configPrefixCallback' |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import fp from 'fastify-plugin' | ||
|
||
function plugin (f, opts, next) { | ||
f.get('/plugin-e', (request, reply) => { | ||
reply.send({ data: opts.e }) | ||
}) | ||
|
||
next() | ||
} | ||
|
||
export default fp(plugin, { name: 'plugin-e' }) | ||
export const autoConfig = (fastify) => { | ||
return { e: 'test-4-' + fastify.root } | ||
} |