Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nitroApp.h3App.use() isn't working #14533

Closed
modelair opened this issue Aug 11, 2022 · 7 comments
Closed

nitroApp.h3App.use() isn't working #14533

modelair opened this issue Aug 11, 2022 · 7 comments

Comments

@modelair
Copy link

modelair commented Aug 11, 2022

Environment

Nuxt project info: 11:41:02


  • Operating System: Darwin
  • Node Version: v16.15.1
  • Nuxt Version: 3.0.0-rc.6
  • Package Manager: npm@8.11.0
  • Builder: vite

Reproduction

  1. Create a nuxt3 app
  2. Create a nitro plugin
  3. Import it in nuxt.config.ts
// ~/server/nitro/plug.ts
export default (nitroApp) => {
    nitroApp.h3App.use((event) => console.log('hello nitro')) // logs nothing
   
}
// nuxt.config.ts
export default defineNuxtConfig({
    nitro: {
        plugins: ['~/server/nitro/plug.ts']
    }
})

Describe the bug

Nitro plugin h3App.use() isn't works

Additional context

But simple h3app works!

import { createApp } from 'h3'
import { createServer } from 'http'

const app = createApp()
createServer(app).listen(process.env.PORT || 3000)

app.use((event) => console.log('hello'))  // logs 'hello'

I found this when i want try to use express-session with h3 and nuxt3.

import session from 'express-session'
export default async (_nitroApp) => { 
_nitroApp.h3App.use(session({}))
}
@516310460
Copy link
Contributor

Maybe you should use https://nitro.unjs.io/guide/storage.html#defining-mountpoints

@modelair
Copy link
Author

@516310460 not looks like solution

@516310460
Copy link
Contributor

There is no such document now, but I am not sure whether this function is experimental. I will submit a document later to see if it will be included

@516310460
Copy link
Contributor

@danielroe @pi0
nitro is it experimental

@516310460
Copy link
Contributor

@modelair See link: nuxt/framework#6507

@danielroe
Copy link
Member

The issue is that you are adding a route after a catchall middleware (nuxt rendering) so it will never be hit.

This is similar to #14177 and perhaps there is a use case for adding middleware in the same way that you can now to nitroApp.router.use('/some/route', handler).

@516310460
Copy link
Contributor

The issue is that you are adding a route after a catchall middleware (nuxt rendering) so it will never be hit.

This is similar to #14177 and perhaps there is a use case for adding middleware in the same way that you can now to nitroApp.router.use('/some/route', handler).

nitro is it experimental

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants