D
D
decvdance2022-02-21 21:15:09
API
decvdance, 2022-02-21 21:15:09

Why is Next JS not proxying api requests?

I am new to next js and I am facing the following issue:
In my next application I am using rewrites to bypass cors during api requests.

async rewrites() {
    return [
      {
        source: '/api/:path*',
        destination: 'http://localhost:82/api/:path*',
        
      },
      {
        source: '/ua/api/:path*',
        destination: 'http://localhost:82/ua/api/:path*',
      },
    ]
  },

And I have the following route:
/checkout/error
But when I make a request to the api, the url part of the page is substituted into the request in this request. It looks like this:
Request URL: http://localhost:3001/en/checkout/en/api/v2/pick-number/order/token/some-token

Here is the request:
axios.get(`/en/api/pick-number/order/token/${token}`)

And if I make a request without a locale, everything goes fine. Also, if the route is not nested, for example, just "/checkout", then everything works correctly. For localization I use i18n.
Help me understand what the problem is, I have already gone through all the possible options, nothing works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
black1277, 2022-02-21
@black1277

Add a line to your package.json file
"proxy": "http://localhost:82",

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question