XMLHttpRequest cannot load http://nginx/api/products due to access control checks

I’m building a Laravel + Nuxt app. It’s running in docker nginx. I also have barryvdh/laravel-cors package with default settings.

I have categories and products that belong to those categories. I can get list of categories from
http://nginx/api/categories. However http://nginx/api/products?category=shoes fails with the following error:

XMLHttpRequest cannot load http://nginx/api/products?category=shoes due to access control checks.

Furthermore, I get this error only when I click on a category link on the page. If I copy/paste the link to the address bar or refresh the page everything works fine.

My docker-compose.yaml

version: '3'

...

nginx:
  build:
    context: docker/nginx
    dockerfile: Dockerfile
  volumes:
    - ./:/var/www
    - ./docker/nginx/logs:/var/log/nginx
  ports:
    # Nuxt port
    - 80:80
    # Laravel port
    - 8081:81
  links:
    - node
    - php-fpm

php-fpm:
  build:
    context: docker/php-fpm
    dockerfile: Dockerfile
  volumes:
    - ./api:/var/www/api
  environment:
    # If you down want to use xDebug, set remote_enable=0
    XDEBUG_CONFIG: "remote_enable=1"
    PHP_IDE_CONFIG: "serverName=Docker"
  links:
    - postgres
    - redis

node:
  build:
    context: docker/node
    dockerfile: Dockerfile
  volumes:
    - ./client:/var/www/client
...

In nuxt.config.js I have the following:

modules: [
  '@nuxtjs/axios',
],
axios: {
  baseURL: 'http://nginx:80/api',
},

When I try baseURL http://localhost:80/api nothing works at all. With http://nginx:80/api at least I can get categories, which suggests that this should be correct.

Source: StackOverflow