question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix type information to allow express middlewares

See original GitHub issue

If you use an express-middleware (such as session or passport), one gets the following typescript error:

Type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is not comparable to type 'EventHandler<any>'.

Example-code:

import session from 'express-session'
import passport from 'passport'
import { createApp } from 'h3'

const app = createApp()
app.use(session())
app.use(passport.initialize())

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pi0commented, Oct 18, 2022

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))
1reaction
tobiasdiezcommented, Aug 31, 2022

@NozomuIkuta please have look at this ts Playground. The app.use calls are showing ts errors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express cors middleware
allowedHeaders : Configures the Access-Control-Allow-Headers CORS header. Expects a comma-delimited string (ex: 'Content-Type,Authorization') or an array (ex: ...
Read more >
How to extend the Express Request object in TypeScript
Let's learn how to extend the Request type in TypeScript to make its instances store custom data you can use at the controller...
Read more >
javascript - Passing variables to the next middleware using ...
This property is useful for exposing request-level information such as the request path name, authenticated user, user settings, and so on.
Read more >
How To Use And Write Express Middleware
Middleware in Express is one of the easiest ways to create DRY and well written code which is why it is crucial to...
Read more >
Middleware in Express.js
Middleware functions execute some code that can have side effects on the app, and usually add information to the request or response objects....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found