-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "composedPlugin should have its own prefix context (#368…
…)"" This reverts commit 65c3dd1.
- Loading branch information
1 parent
bcca903
commit 5918421
Showing
9 changed files
with
150 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
const path = require('node:path') | ||
const autoLoad = require('../../../../') | ||
|
||
module.exports = async function (fastify) { | ||
fastify.register(autoLoad, { | ||
dir: path.join(__dirname, '/routes-a'), | ||
autoHooks: true, | ||
cascadeHooks: true | ||
}) | ||
|
||
fastify.register(autoLoad, { | ||
dir: path.join(__dirname, '/routes-b'), | ||
autoHooks: true, | ||
cascadeHooks: true, | ||
options: { prefix: 'custom-prefix' } | ||
}) | ||
} |
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,7 @@ | ||
module.exports = async function (app) { | ||
app.setNotFoundHandler((request, reply) => { | ||
reply.code(404) | ||
.header('from', 'routes-a/child') | ||
.send() | ||
}); | ||
} |
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,7 @@ | ||
'use strict' | ||
|
||
module.exports = async function (app) { | ||
app.get('/', async function (req, reply) { | ||
reply.send() | ||
}) | ||
} |
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,7 @@ | ||
module.exports = async function (app) { | ||
app.setNotFoundHandler((request, reply) => { | ||
reply.code(404) | ||
.header('from', 'routes-a/sibling') | ||
.send() | ||
}); | ||
} |
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,7 @@ | ||
'use strict' | ||
|
||
module.exports = async function (app) { | ||
app.get('/', async function (req, reply) { | ||
reply.send() | ||
}) | ||
} |
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,7 @@ | ||
module.exports = async function (app) { | ||
app.setNotFoundHandler((request, reply) => { | ||
reply.code(404) | ||
.header('from', 'routes-b') | ||
.send() | ||
}); | ||
} |
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,7 @@ | ||
'use strict' | ||
|
||
module.exports = async function (app) { | ||
app.get('/', async function (req, reply) { | ||
reply.send() | ||
}) | ||
} |
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,80 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const Fastify = require('fastify') | ||
|
||
t.plan(19) | ||
|
||
const app = Fastify() | ||
|
||
app.register(require('./autohooks')) | ||
|
||
app.setNotFoundHandler((request, reply) => { | ||
reply.code(404) | ||
.header('from', 'root') | ||
.send() | ||
}) | ||
|
||
app.ready(function (err) { | ||
t.error(err) | ||
|
||
app.inject({ | ||
url: '/not-exists' | ||
}, function (err, res) { | ||
t.error(err) | ||
t.equal(res.headers.from, 'root') | ||
|
||
t.equal(res.statusCode, 404) | ||
}) | ||
|
||
app.inject({ | ||
url: '/child' | ||
}, function (err, res) { | ||
t.error(err) | ||
|
||
t.equal(res.statusCode, 200) | ||
}) | ||
|
||
app.inject({ | ||
url: '/child/not-exists' | ||
}, function (err, res) { | ||
t.error(err) | ||
t.equal(res.headers.from, 'routes-a/child') | ||
|
||
t.equal(res.statusCode, 404) | ||
}) | ||
|
||
app.inject({ | ||
url: '/sibling' | ||
}, function (err, res) { | ||
t.error(err) | ||
|
||
t.equal(res.statusCode, 200) | ||
}) | ||
|
||
app.inject({ | ||
url: '/sibling/not-exists' | ||
}, function (err, res) { | ||
t.error(err) | ||
t.equal(res.headers.from, 'routes-a/sibling') | ||
|
||
t.equal(res.statusCode, 404) | ||
}) | ||
|
||
app.inject({ | ||
url: '/custom-prefix' | ||
}, function (err, res) { | ||
t.error(err) | ||
|
||
t.equal(res.statusCode, 200) | ||
}) | ||
|
||
app.inject({ | ||
url: '/custom-prefix/not-exists' | ||
}, function (err, res) { | ||
t.error(err) | ||
t.equal(res.headers.from, 'routes-b') | ||
|
||
t.equal(res.statusCode, 404) | ||
}) | ||
}) |