404 not found on app httpProxyMiddleware
Unanswered
Flemish Giant posted this in #help-forum
Flemish GiantOP
Hi, I am using app proxy router to proxy requests to linkedin but getting 404 not found when hitting endpoint. I have a route file in ./src/app/api/proxy/[...all].ts with the following content
import { NextApiRequest, NextApiResponse } from 'next';
import httpProxyMiddleware from 'next-http-proxy-middleware';
export default (req: NextApiRequest, res: NextApiResponse) =>
httpProxyMiddleware(req, res, {
// Target API that we want to proxy the requests to
target: 'https://api.linkedin.com',
// Optionally rewrite the path. We can remove the '/api/proxy' part.
pathRewrite: {
'^/api/proxy/linkedin': '', // Removes /api/proxy/linkedin from the URL, leaving just /v2/me
},
// Enable change of origin for the proxy
changeOrigin: true,
});
, I am trying to redirect a request from my client const response = await axios.get("/api/proxy/linkedin/v2/me", {
headers: {
Authorization: `Bearer ${user?.oAuthAccessToken}`,
},
}); , but I get a http://localhost:3000/api/proxy/linkedin/v2/me 404 (Not Found) , I want to map http://localhost:3000/api/proxy/linkedin/v2/me to http://linkedin/v2/me , is there something wrong in my setup?