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

Express middlewares in route handlers (support passport in app router) #228

Open
eric-burel opened this issue Jun 22, 2023 · 0 comments
Open

Comments

@eric-burel
Copy link

eric-burel commented Jun 22, 2023

Hi,
If I understand correctly, so far the Express wrapper only targets API routes, not route handlers. This is a tad more complicated to setup because route handlers use a different structure for the request/response (the web platform ones, built-in node/browser and used by fetch) than Express.

Can you please confirm me that this is not possible in next-connect right now?

In the meantime here is what I've stated to work on to bypass this issue: https://github.com/Devographics/Monorepo/blob/develop/surveyform/src/app/api/nespresso.ts

The API is like so:

export function POST(req: NextRequst) {
   return nespresso(
    // a normal Express middleware
     (req, res, next) => { next() },
    (req, res, next) => { res.send("foobar") }
   ) // returns  Next Response
}

Feel free to reuse this code if that sounds relevant to you. The typings are giving me a hard time (somehow "res.status" is not found, and "Handler" type is not accepted as a middleware) and features are missing but it roughly works otherwise.

After a few more experiments, I fail to properly create an Express response/request directly from Express codebase, this forces me to mimick all features but then writing the request seems to fail.

Setting relevant methods by hand, it mostly works however somehow passport can't set "res.user", I can't tell why, while it can set "_passport". I don't have a minimal repro yet.

@eric-burel eric-burel changed the title Express wrapper + route handlers Express wrapper + route handlers (support passport in app router) Jun 22, 2023
@eric-burel eric-burel changed the title Express wrapper + route handlers (support passport in app router) Express middlewares in route handlers (support passport in app router) Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant