Vladyslav
Vladyslav

Reputation: 91

Next Js does not proxying API requests

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.

Upvotes: 1

Views: 1675

Answers (0)

Related Questions