0

I'm new to next and I'm facing the following problem and i will be glad for your help

In my next application i use rewrites to get around cors during api requests.

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

And i have the following route in my application

/checkout/error

But when I make a request to the api, part of the page url is substituted into the request to the api.

Request URL: http://localhost:3001/en/checkout/en/api/v2/pick-number/order/token/62111ff5e3a0

Here is my request:

axios.get(`/en/api/pick-number/order/token/${token}`)

However, if I make a request without specifying the locale, everything goes fine. Also, if the route is not nested, for example just "/checkout", then everything works correctly. For localization i use i18n. I am frustrated with this problem, please help.

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Vladyslav
  • 51
  • 4
  • API routes must be under the `/pages/api`, meaning the paths should always started with `/api`. Try replacing the `source` in your second rewrite with `'/api/en/:path*'` (but keep the `destination` as is), then make the request against ``axios.get(`/api/en/pick-number/order/token/${token}`)``. – juliomalves Feb 21 '22 at 22:17
  • @juliomalves unfortunately it doesn't work – Vladyslav Feb 22 '22 at 09:23

0 Answers0