所以我只是在Heroku上部署了我的应用程序.我有一个应用程序,其中前端向后端发送登录请求.但我无法摆脱Heroku端的CORS问题(本地端没有问题).
我的前台是https://yourclimbfrontend.herokuapp.com/
这就是我调整CORS的方式:
fun Application.configureHTTP() {
install(CORS) {
allowMethod(HttpMethod.Options)
allowMethod(HttpMethod.Put)
allowMethod(HttpMethod.Delete)
allowMethod(HttpMethod.Get)
allowMethod(HttpMethod.Patch)
allowHeader(HttpHeaders.Authorization)
allowHeader("cart_session")
exposeHeader("cart_session")
allowHeader("MyCustomHeader")
allowHeader("X-Requested-With")
allowHeader("X-HTTP-Method-Override")
allowHeader("Content-Type")
allowHeader("Authorization")
allowHeader("Accept")
allowHeader("Access-Control-Allow-Credentials")
allowHeader("Accept")
allowHeader("Access-Control-Allow-Origin")
allowHost("https://yourclimbfrontend.herokuapp.com")
// allowHost("localhost:3000")'
// anyHost()
}
}
如果我开了localHost:3000
,它就能在我的本地机器上运行;如果我开着anyHost()
,它就能在Heroku端运行.但我读到过,一个人应该避免anyHost()
,所以我try 只让https://yourclimbfrontend.herokuapp.com
发送请求.
我是不是在allowHost
里用错了链接?或者我需要额外的线路才能允许Heroku?