Я пытаюсь включить CORS для моего API (я использую Symfony 4.2 + api_platform)
Я установил NelmiosCors
composer req "nelmio/cors-bundle"
Добавил его в Kernel.php
$bundles = array(
new Nelmio\CorsBundle\NelmioCorsBundle(),
);
И добавил это в services.yaml
nelmio_cors:
defaults:
allow_credentials: false
allow_origin: []
allow_headers: ['Content-Type']
allow_methods: []
expose_headers: []
max_age: 0
hosts: []
origin_regex: false
forced_allow_origin_value: ~
paths:
'^/api/':
allow_origin: ['*']
allow_headers: ['X-Custom-Auth', 'Content-Type']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE']
max_age: 3600
'^/':
origin_regex: true
allow_origin: ['^http://localhost:[0-9]+']
allow_headers: ['X-Custom-Auth', 'Content-Type']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE']
max_age: 3600
hosts: ['^api\.']
Но когда я делаю сервер: запустить, я получаю сообщение об ошибке:
In FileLoader.php line 166:
!!
!! The configuration key "defaults" is unsupported for definition "nelmio_cors
!! " in "/mnt/c/dev/api/config/services.yaml". Allowed configuration keys are
!! "alias", "parent", "class", "shared", "synthetic", "lazy", "public", "abstr
!! act", "deprecated", "factory", "file", "arguments", "properties", "configur
!! ator", "calls", "tags", "decorates", "decoration_inner_name", "decoration_p
!! riority", "autowire", "autoconfigure", "bind" in /mnt/c/dev/api/config/serv
!! ices.yaml (which is loaded in resource "/mnt/c/dev/api/config/services.yaml
!! ").
!!
!!
!! In YamlFileLoader.php line 813:
!!
!! The configuration key "defaults" is unsupported for definition "nelmio_cors
!! " in "/mnt/c/dev/api/config/services.yaml". Allowed configuration keys are
!! "alias", "parent", "class", "shared", "synthetic", "lazy", "public", "abstr
!! act", "deprecated", "factory", "file", "arguments", "properties", "configur
!! ator", "calls", "tags", "decorates", "decoration_inner_name", "decoration_p
!! riority", "autowire", "autoconfigure", "bind".
Я следовал руководству NelmiosCors + руководству api_platform, теперь я не знаю, что я могу сделать.
Будет полезна помощь.