【问题标题】:Cors Policy doesn't take my specified Methods Express GatewayCors 政策不采用我指定的方法 Express 网关
【发布时间】:2020-05-03 19:40:55
【问题描述】:

我有一个 Angular 应用程序,我使用 Express Gateway 对后端的请愿书进行一些控制,除了我的 Cors 方法外,一切正常,我只想允许 GET、PUT、POST,但即使我没有'不要把它仍然可以访问的DELETE方法,我不知道我错在哪里,我已经阅读了文档。

{
"http": {
    "port": 8080,
},
"admin": {
    "port": 9876,
    "host": "localhost"
},
"apiEndpoints": {
    "apiAngular": {
        "host": "13.84.42.7",
        "paths": "/api/v3/*"
    },
    "api": {
        "host": "localhost",
        "paths": "/ip"
    }
},
"serviceEndpoints": {
    "service_apiAngular": {
        "url": "http://localhost:4002"
    },
    "httpbin": {
        "url": "https://httpbin.org"
    }
},
"policies": [
    "cors",
    "basic-auth",
    "expression",
    "key-auth",
    "log",
    "oauth2",
    "proxy",
    "rate-limit",
    "jwt"
],
"pipelines": {
    "pipeline_apiAngular": {
        "apiEndpoints": [
            "apiAngular"
        ],
        "policies": [
            {
                "cors":{
                    [
                        "action":{
                            "origin": "*",
                            "methods": "GET,PUT,POST",
                            "preflightContinue": false,
                            "optionsSuccessStatus": 204
                        }
                    ]

                }
            },
            {
                "rate-limit": [
                    {
                        "action": {
                            "max": 15,
                            "windowMs": 1200
                        }
                    }
                ]
            },
            {
                "proxy": [
                    {
                        "action": {
                            "serviceEndpoint": "service_apiAngular"
                        }
                    }
                ]
            }
        ]
    },
    "default": {
        "apiEndpoints": [
            "api"
        ],
        "policies": [
            {
                "proxy": [
                    {
                        "action": {
                            "serviceEndpoint": "httpbin",
                            "changeOrigin": true
                        }
                    }
                ]
            }
        ]
    }
}

}

【问题讨论】:

    标签: angular express methods cors gateway


    【解决方案1】:

    https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSMethodNotFound

    使用 Access-Control-Allow-Methods 来允许你想要允许的 http 请求方法

    【讨论】:

    • 但我仍然想使用 Express Gateway,并在那里管理 Access-Control-Allow-Methods。
    猜你喜欢
    • 2021-06-12
    • 2015-06-03
    • 2020-03-12
    • 2021-06-23
    • 2021-04-27
    • 2014-05-03
    • 1970-01-01
    • 2021-02-13
    • 2020-12-23
    相关资源
    最近更新 更多