【发布时间】:2019-03-14 19:10:03
【问题描述】:
我正在尝试使用 Webjar 在 Play Scala 模板中实现 PayPal 结帐按钮。 这是 sbt 中的定义:
"org.webjars" %% "webjars-play"% "2.6.1",
"org.webjars"% "bootstrap"% "4.2.1" exclude ("org.webjars", "jquery"),
"org.webjars"% "jquery"% "3.2.1",
这是模板中的导入:
@import org.webjars.play.WebJarsUtil
我还包括 jQuery、Popper.js 和 bootstrap javaScript 插件脚本。
以下 html 在浏览器中运行良好:
<!DOCTYPE html>
<html>
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script
src="https://www.paypal.com/sdk/js?client-id=sb">
</script>
</head>
<body>
<div id="paypal-button-container"></div>
<script>
paypal.Buttons().render('#paypal-button-container');
</script>
</body>
</html>
但它不会在播放模板中呈现 感谢您帮助解决这个问题
Krzysztof,通过以下修改 Play 配置解决了问题:
# Security Filter Configuration - Content Security Policy
play.filters.headers {
contentSecurityPolicy = "default-src 'self' * .paypal.com;"
contentSecurityPolicy = $ {play.filters.headers.contentSecurityPolicy} "img-src 'self' data: * .fbcdn.net * .twimg.com * .googleusercontent.com * .xingassets.com vk.com * .yimg.com secure .gravatar.com; "
contentSecurityPolicy = $ {play.filters.headers.contentSecurityPolicy} "style-src 'self' 'unsafe-inline' cdnjs.cloudflare.com maxcdn.bootstrapcdn.com cdn.jsdelivr.net fonts.googleapis.com;"
contentSecurityPolicy = $ {play.filters.headers.contentSecurityPolicy} "font-src 'self' fonts.gstatic.com fonts.googleapis.com cdnjs.cloudflare.com;"
contentSecurityPolicy = $ {play.filters.headers.contentSecurityPolicy} "script-src 'self' 'unsafe-inline' 'unsafe-eval' cdnjs.cloudflare.com * .paypal.com;"
contentSecurityPolicy = $ {play.filters.headers.contentSecurityPolicy} "connect-src 'self' twitter.com * .xing.com * .paypal.com;"
谢谢你¡
我还想从 Play 2.6.11 迁移到 Play 2.7.0。但是,在包含插件和 Requirejs 的依赖项后,执行时出现以下错误:
ProvisionException: Unable to provision, see the following errors: 1) Error injecting constructor, java.lang.AbstractMethodError: Method org / webjars / play / RequireJS.play $ api $ mvc $ Results $ _setter_ $ PreconditionRequired_ $ eq (Lplay / api / mvc / Results $ Status;) V is abstract at org.webjars.play.RequireJS. <init> (RequireJS.scala: 9) at org.webjars.play.RequireJS.class (RequireJS.scala: 9) while locating org. webjars.play.RequireJS for the 2nd parameter of webjars.Routes. <init> (Routes.scala: .........
我想知道困难可能是什么 非常感谢
【问题讨论】:
-
您是否检查过,模板的输出 HTML 呈现的是什么?要检查它,只需打开页面并按
ctrl+u。你检查控制台输出了吗?您通常可以使用ctrl+c或F12打开浏览器控制台。 -
Krzysztof,控制台消息如下:“内容安全策略:此页面的选项已阻止在 paypal.com/sdk/js?client-id=sb (script-src) 加载资源。”似乎 Play 正在阻止 PayPal 页面。如何允许加载此资源?谢谢!
-
这似乎是 CSP 的问题。你能展示你的旋转模板吗?
标签: javascript scala paypal playframework-2.3 webjars