Mulesoft не может найти прослушиватель запросов OPTIONS

Я сделал API в Mulesoft, который мне нужно использовать из интерфейса Angular. Запросы GET работают нормально, но когда я пытаюсь отправить запросы POST / DELETE, при отправке запроса OPTIONS возникает ошибка (ответ не имеет заголовков cors, а cors настроен правильно). Когда я добавляю одну из своих конечных точек в маршрут сертификата для принятия OPTIONS, она работает нормально. Могу ли я каким-то образом создать глобального слушателя для каждого запроса OPTIONS, отправляемого по любому маршруту. Ниже приведен код соединителя HTTP.

<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="8d79948b-c780-43eb-b7d1-41235210a0ff" basePath="/api" >
    <http:listener-connection host="localhost" port="8081" protocol="HTTP" />
    <http:listener-interceptors >
        <http:cors-interceptor >
            <http:origins >
                <http:origin url="http://localhost:4200" accessControlMaxAge="30000">
                <http:allowed-methods>
                    <http:method methodName="GET" />
                    <http:method methodName="POST" />
                    <http:method methodName="DELETE" />
                    <http:method methodName="OPTIONS" />
                  <http:method methodName="PUT" />
                </http:allowed-methods>
                <http:allowed-headers >
                  <http:header headerName="Content-Type" />
                  <http:header headerName="Access-Control-Allow-Headers" />
                  <http:header headerName="Access-Control-Allow-Origin" />
              </http:allowed-headers>
              <http:expose-headers />
            </http:origin>

            </http:origins>
        </http:cors-interceptor>
    </http:listener-interceptors>
</http:listener-config>

person Dragan Jankovic    schedule 11.06.2020    source источник


Ответы (1)


Это моя конфигурация, вам нужно добавить заголовки экспонирования:

<http:listener-config name="agentportal-httpListenerConfig">
    <http:listener-connection host="0.0.0.0" port="8081" />
    <http:listener-interceptors >
        <http:cors-interceptor allowCredentials="false">
            <http:origins >
                <http:origin url="http://localhost:4200" accessControlMaxAge="30000" >
                    <http:allowed-methods >
                        <http:method methodName="OPTIONS" />
                        <http:method methodName="GET" />
                        <http:method methodName="POST" />
                    </http:allowed-methods>
                    <http:allowed-headers >
                        <http:header headerName="Content-Type" />
                        <http:header headerName="Authorization" />
                        <http:header headerName="Accept" />
                    </http:allowed-headers>
                    <http:expose-headers >
                        <http:header headerName="Access-Control-Allow-Origin" />
                        <http:header headerName="Access-Control-Allow-Methods" />
                        <http:header headerName="Access-Control-Allow-Headers" />
                    </http:expose-headers>
                </http:origin>

            </http:origins>
        </http:cors-interceptor>
    </http:listener-interceptors>
</http:listener-config>
person Aldo Beltrán    schedule 13.06.2020