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?
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.
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:
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.