-
Notifications
You must be signed in to change notification settings - Fork 19
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
ERR_STREAM_WRITE_AFTER_END #21
Comments
Hi @aaaaahaaaaa, |
Try like so import type { NextApiRequest, NextApiResponse } from 'next'
import jwt from 'next-auth/jwt'
import httpProxyMiddleware from 'next-http-proxy-middleware';
export default async (req: NextApiRequest, res: NextApiResponse) => {
const { accessToken } = await jwt.getToken({ req: req, secret: "CHANGE_ME" })
await httpProxyMiddleware(req, res, {
target: 'https://whatever.com',
pathRewrite: { "^/before": '/after' },
headers: { Authorization: `Bearer ${accessToken}` },
});
res.end();
} The main problem is that response is not finished |
Related vercel/next.js#10439 |
Thanks for the feedback. Unfortunately I changed my implementation and have no means to test this at the moment. I'll try again when I have a minute. I'll close this issue for now. |
This issue may have been resolved by #24. |
v^1.0.10 - still getting
import httpProxyMiddleware from 'next-http-proxy-middleware';
import { NextApiRequest, NextApiResponse } from 'next';
import { getSession } from '@auth0/nextjs-auth0';
import * as Sentry from '@sentry/node';
import { initSentry } from 'src/utils/sentry';
export default async (req: NextApiRequest, res: NextApiResponse) =>
httpProxyMiddleware(req, res, {
target: process.env.NEXT_PUBLIC_API_BASE_URL,
// In addition, you can use the `pathRewrite` option provided by `next-http-proxy`
pathRewrite: {
'^/api/rest': '/api',
},
headers: {
Authorization: `Bearer ${getSession(req, res)?.idToken}`,
'Content-Type': 'application/json-patch+json',
},
}).catch(async (error) => {
initSentry();
Sentry.captureException(error);
await Sentry.flush(2000);
}); if I add
|
Also getting |
I added
On top of file and thous errors is not displayed anymore, but not sure is the problem is solved that way |
@all-contributors please add @FDiskas for doc |
I've put up a pull request to add @FDiskas! 🎉 |
First of all: nice lib. AFAICT it's the only clean middleware out there that allows to update the request's headers with NextJS without errors.
I do encounter issues with your middleware though.
I have a fairly simple proxy setup for an API with a dynamic route (using
SWR
on the client side):When sending requests via to the proxy for with the same path, it works nicely. When requests with different paths go through the middleware, I see the following error (not right away, after a couple of minutes):
And prior to that, NextJS's server shows this kind of warning:
The text was updated successfully, but these errors were encountered: