gpt4 book ai didi

playframework - 使用Electron App玩2.6-CORS

转载 作者:行者123 更新时间:2023-12-03 12:35:45 27 4
gpt4 key购买 nike

我在Play框架中遇到无效的CORS问题。
[warn] p.f.c.CORSFilter - Invalid CORS request;Origin=Some(file://);Method=POST;Access-Control-Request-Headers=None
如何配置以使其与Electron App一起使用?

这是我当前的application.conf:

play.application.loader = "modules.ApplicationLoaderConfig"
play.modules.enabled += "play.modules.reactivemongo.ReactiveMongoModule"
play.filters.enabled += "play.filters.cors.CORSFilter"
play.filters.cors {
allowedOrigins = null, # This means "all"
allowedHttpMethods = null, # This means "all"
exposedHeaders = ["Authorization", "Content-Length", "Content-Type", "Content-disposition"],
preflightMaxAge = 7 days
}

我也尝试过删除过滤器..仅保留:
play.application.loader = "modules.ApplicationLoaderConfig"
play.modules.enabled += "play.modules.reactivemongo.ReactiveMongoModule"

但是仍然无法使其正常工作。

在 Electron 方面,我还尝试了 webSecurity选项:
app.on('ready', () => {
win = new BrowserWindow({
webPreferences: { webSecurity: false }
});

我尝试了 falsetrue,但没有区别。

提前致谢!

最佳答案

尝试设置此配置

play.filters.cors.serveForbiddenOrigins = true

实际上,将Play与Electron Apps一起使用时会遇到一些问题,因为当他们请求某项内容时,其来源将被设置为"file",并且默认情况下Play不允许这样做。

请参阅这些链接以供引用。
  • https://github.com/Hub-of-all-Things/HAT2.0/pull/39
  • https://github.com/playframework/playframework/issues/8037
  • https://github.com/playframework/playframework/pull/7341

  • 希望这可以帮助!

    关于playframework - 使用Electron App玩2.6-CORS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47602675/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com