-
Notifications
You must be signed in to change notification settings - Fork 203
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
Fix type information to allow express middlewares #146
Comments
@pi0 explains it in #73 why they are changing middleware signature. In my understanding, h3 is aiming to be environment-agnostic server framework for future, even with trade-offs like abandoning the existing ecosystem. One possible compromise might be to provide a glue function that convert // This is a virtual code
// `eventify` passes `req/res` and `next` function to the wrapped middleware
app.use(eventify(session())) |
Sorry, I should have been more precise. There is already such a wrapper in place (und the hood) and the above code does work. It's only that TypeScript is throwing an error, so I guess something is off here Line 23 in 4b83bdf
|
Sorry, I misunderstood you. By the way, I couldn't instantly reproduce the error that you are taking about. |
@NozomuIkuta please have look at this ts Playground. The |
For your information, I found that @pi0 had created a branch where he is removing compatibility with legacy Express-style middleware whose signature is By the way, it's written in README that:
Once the branch is merged, the "maximum" compatibility get to be "zero" (note: this change has been planned in #73). So, at this moment, all options we have would be (1) to make up h3-native auth solution by ourselves rather than making h3 complex by adding Express middleware support, or (2) to give a support to authors so that they can do it for us (e.g. sponsoring via GitHub). That's just because h3 is an OSS. |
Middleware made for express, depend on specific auegmentations coming from express app itself (.json(), .cookie(), etc) In order to use express middleware with h3, you need to first create an express app: const app = h3.createApp()
const expressApp = express()
expressApp.use(expressMiddleware()
app.use(h3.fromNodeMiddleware(expressApp)) |
If you use an express-middleware (such as session or passport), one gets the following typescript error:
Example-code:
The text was updated successfully, but these errors were encountered: