TheSadMidDeveloper
TheSadMidDeveloper
Explore posts from servers
NNuxt
Created by TheSadMidDeveloper on 10/11/2024 in #❓・help
Server middleware ordering with modules
Sorry daniel and thank you
8 replies
NNuxt
Created by TheSadMidDeveloper on 10/11/2024 in #❓・help
Server middleware ordering with modules
If you want more context, here: Say you're authoring a module. This is your middleware:
// runtime/server/middleware.ts
export default eventHandler((event ) => {
event.context.hello = 'world'
})
// runtime/server/middleware.ts
export default eventHandler((event ) => {
event.context.hello = 'world'
})
and in your module
addServerHandler({
middleware: true,
handler: resolver.resolve('./runtime/server/middleware'),
})
addServerHandler({
middleware: true,
handler: resolver.resolve('./runtime/server/middleware'),
})
and in your app, you install it like so:
export default defineNuxtConfig({
modules: ['your-nuxt-module'],
})
export default defineNuxtConfig({
modules: ['your-nuxt-module'],
})
Hooray! The middleware from module is installed. Now, you want to access that in your own custom middleware...
// server/middlewares/100.global.ts - see, it doesnt work even when you prefix it with that haha
export default eventHandler((event ) => {
console.log(event.context.hello) // undefined undefined undefined
})
// server/middlewares/100.global.ts - see, it doesnt work even when you prefix it with that haha
export default eventHandler((event ) => {
console.log(event.context.hello) // undefined undefined undefined
})
Oh no, the hello context is undefined!
8 replies