-
Notifications
You must be signed in to change notification settings - Fork 20
Does this library support Next 13 app dir ? #83
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
Comments
Hi @wangwailok Please let me know if I'm misunderstanding. |
It seems difficult to see this library as a kind of 'middleware' that is currently called by Next.js. This library has been used since Next.js v9, and at that time, libraries that handle APIs were called |
I am using next js 13 with App dir, the type of request object has been changed to "NextRequest" and cannot pass inot the proxy middleware anymore |
@wangwailok Because, this library is a middleware(handler) for handling API requests, and Please see links below
Please let me know if i'm missing something. |
Hi, @pluce // e.g.,
...
export async function POS(...) {
return httpProxyMiddleware(... {}); // <- This function must return
} |
Plzz help me!! Error: Cannot set property body of # which has only a getter |
Hi, @stoompa Could you please share the your project repository? |
I cannot show the whole code since it is enterprise, but this is how we are using this library: export async function GET(req: NextApiRequest, res: NextApiResponse) {
const onProxyInit = await getOnProxyInit(req);
const proxyOptions: NextHttpProxyMiddlewareOptions = {
onProxyInit,
changeOrigin: true,
target: REPORTS_URL,
pathRewrite: [{ patternStr: '/api/reports', replaceStr: '' }]
};
await httpProxyMiddleware(req, res, proxyOptions);
} |
You must return the result of the export async function GET(req: NextApiRequest, res: NextApiResponse) {
const onProxyInit = await getOnProxyInit(req);
const proxyOptions: NextHttpProxyMiddlewareOptions = {
onProxyInit,
changeOrigin: true,
target: REPORTS_URL,
pathRewrite: [{ patternStr: '/api/reports', replaceStr: '' }]
};
return await httpProxyMiddleware(req, res, proxyOptions);
}
... |
|
@stoompa ...
export const config = {
api: {
// Enable `externalResolver` option in Next.js
externalResolver: true,
},
}
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const onProxyInit = await getOnProxyInit(req);
const proxyOptions: NextHttpProxyMiddlewareOptions = {
onProxyInit,
changeOrigin: true,
target: REPORTS_URL,
pathRewrite: [{ patternStr: '/api/reports', replaceStr: '' }]
};
return await httpProxyMiddleware(req, res, proxyOptions);
};
export default handler;
... If that doesn't work, please let me known the next.js version so I can check further. |
@stegano thanks for the help, unfortunately it does not work. exporting the handler as default only works with the pages directory, and I think we all have the same issue when using the |
You're right. This library might not work properly with Next.js App Directory. It is indeed an older library, and Next.js has introduced the 'rewrites' feature which could potentially replace the functionality you're seeking from this library. Have you tried using the 'rewrites' feature yet? If not, it's worth looking into. If you have chosen not to use 'rewrites', could you provide some insight into your decision? |
I have checked out |
Sorry, I'm late with my reply. I'm not sure what you're trying to do |
Hi, even if your idea is correct in the vast majority of cases (i.e., "rewrites" will solve the problem in most cases), there are some special cases, such as when I plan to use an agent (e.g., my proxy target has to be accessed through http_proxy), where I can't add an agent using rewrites, which was possible with the previous http-proxy-middleware works. I still hope you can try to provide support for |
So despite of multiple examples in this thread, /app routing is not working with next-http-proxy-middleware as of today correct? |
@rayrapetyan If anyone knows a better way, please let me know. |
Somehow it didn't work even with page router... I've ended up using a stand-alone nginx instance just for routing purposes. |
@rayrapetyan |
@stegano |
@lvilasboas-dti |
I just now realized you said you were using it in |
haha.. yeah.. sorry for that |
The type requests in the new route system changed from NextApiequest to NextRequest
and the middleware seems cannot work accordingly. any workaround?
The text was updated successfully, but these errors were encountered: