使用HOCON变量在游戏框架中与允许素的CORS问题2.8.15
有一个Java应用程序,该应用程序使用Java,Scala,PlayFramework和Maven。
jdk 11.0.14
play2 version 2.8.15
scala.version 2.12.15
play2.plugin.version 1.0.0-rc6-SNAPSHOT
sbt-compiler.plugin.version 1.0.0
application.conf
play.application.loader = "loader.BasicApplicationLoader"
play.modules.disabled += "play.core.ObjectMapperModule"
play.modules.enabled += "modules.WebObjectMapperModule"
play.modules.enabled += "modules.StartUpModule"
play.modules.enabled += "modules.ClusterMonitoringModule"
play.modules.enabled += "com.kenshoo.play.metrics.PlayModule"
play.filters.enabled = [
"play.filters.gzip.GzipFilter",
"com.kenshoo.play.metrics.MetricsFilter",
"http.filters.ClusterStatusFilter",
"play.filters.cors.CORSFilter"
]
play.http.actionCreator = "http.BasicActionCreator"
play.http.requestHandler = "http.WebHttpRequestHandler"
play.http.errorHandler = "http.BasicErrorHandler"
server1.host="http://localhost:9000/"
server2.host="http://localhost:2000/"
server3.host="http://localhost:11000/"
play.filters.cors {
pathPrefixes = ["/"]
allowedOrigins = [${?server1.host}, ${?server2.host}, ${?server3.host}]
allowedHttpMethods = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
allowedHttpHeaders = ["Accept", "Origin", "Content-Type"]
exposedHeaders = ["X-TOTAL-PAGE-COUNT", "X-TOTAL-ELEMENT-COUNT"]
preflightMaxAge = 1 hour
}
response.delay.milliseconds=500
'https:// localhost:8080'从Origin'https:// localhost:9000'访问xmlhttprequest:no'access-control-allow-allow-Origin'标头,否则已阻止了'https:// localhost:9000'资源。
到目前为止,我尝试了什么?
我已经检查了服务器,如果正确解释了所使用的变量,则已经部署了该服务器,是的。我需要使用这样的变量,因为根据所需的环境,该URL的值在部署时间在服务器上超过了。
试图添加裸露的访问者访问控制者 - 允许原子,试图将其添加到允许的httpheaders中,而没有运气。
There is a java application, which use java, scala, playframework and maven.
jdk 11.0.14
play2 version 2.8.15
scala.version 2.12.15
play2.plugin.version 1.0.0-rc6-SNAPSHOT
sbt-compiler.plugin.version 1.0.0
application.conf
play.application.loader = "loader.BasicApplicationLoader"
play.modules.disabled += "play.core.ObjectMapperModule"
play.modules.enabled += "modules.WebObjectMapperModule"
play.modules.enabled += "modules.StartUpModule"
play.modules.enabled += "modules.ClusterMonitoringModule"
play.modules.enabled += "com.kenshoo.play.metrics.PlayModule"
play.filters.enabled = [
"play.filters.gzip.GzipFilter",
"com.kenshoo.play.metrics.MetricsFilter",
"http.filters.ClusterStatusFilter",
"play.filters.cors.CORSFilter"
]
play.http.actionCreator = "http.BasicActionCreator"
play.http.requestHandler = "http.WebHttpRequestHandler"
play.http.errorHandler = "http.BasicErrorHandler"
server1.host="http://localhost:9000/"
server2.host="http://localhost:2000/"
server3.host="http://localhost:11000/"
play.filters.cors {
pathPrefixes = ["/"]
allowedOrigins = [${?server1.host}, ${?server2.host}, ${?server3.host}]
allowedHttpMethods = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
allowedHttpHeaders = ["Accept", "Origin", "Content-Type"]
exposedHeaders = ["X-TOTAL-PAGE-COUNT", "X-TOTAL-ELEMENT-COUNT"]
preflightMaxAge = 1 hour
}
response.delay.milliseconds=500
According to the Play documentation this should work, but it does not, i get the cors error:
Access to XMLHttpRequest at 'https://localhost:8080' from origin 'https://localhost:9000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
What I have tried so far?
I have checked on the server, where I have deployed if the variables used are correctly interpreted, and yes, they are. I need to use variables like this, because the values of this urls are overriden on the server at deploy time according to the environment needed.
Tried to add in the exposedHeader the Access-Control-Allow-Origin, tried to add it in the allowedHttpHeaders and no luck..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,在发布了这个问题之后,我弄清楚了这个问题。
问题是那些服务器值:
因为浏览器为Origin“ http:// localhost:9000”而无需斜线,这就是为什么差异的原因。
So, after posting this questions I have figured out the question.
The issue were those server values:
For the browser was origin "http://localhost:9000" without slash and that is why the difference.