我在过去的工作中遇到404错误。
10:35:40.588 [warn] application - [onHandlerNotFound] GET /assets/javascripts/require.js?v=807475 - 127.0.0.1
我检查了sbt-rjs插件的配置指南: https://www.playframework.com/documentation/2.4.x/RequireJS-support
但是我已经设置了所有内容 - 因为它在2.3
上工作正常plugin.sbt:
// The Typesafe repository resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.0")
// BuildInfo available in java addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.2.5")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-stylus" % "1.0.1")
addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
build.sbt:
...
// Asset building pipeline
pipelineStages := Seq(rjs,gzip)
...
HTML模板: require = { urlArgs:' v =@Urls.ASSETS_VERSION', waitSeconds:180 };
<script data-main="@Urls.assetWithoutVersion("javascripts/main.js")" src="@Urls.asset("javascripts/require.js")" type="text/javascript"></script>
HTML呈现:
<script>
require = {
urlArgs: 'v=807475',
waitSeconds: 180
};
</script>
<script data-main="//local.prizeo.com:9000/assets/javascripts/main.js" src="//local.prizeo.com:9000/assets/javascripts/require.js?v=807475" type="text/javascript"></script>
其他人遇到过这个问题吗?
谢谢!
编辑:
可能不重要的信息,但添加它是为了完整性。 我们使用自定义Urls类来使用云前端:
public static String assetWithoutVersion(String path) {
if (Protocols.HTTP.isUsed(path) || Protocols.HTTPS.isUsed(path)) {
if(Protocols.HTTP.isUsed(path)) {
//this should be avoided, since some browsers may refuse o load unsecured content
DLogger.warn(TAG, "Asset file '" + path + "' has the protocol specified");
}
} else if(Protocols.NONE.isUsed(path)) {
//this is fine
} else {
if (USE_CLOUDFRONT_ASSETS) {
path = Protocols.NONE + getCloudfrontUrl() + "/assets/" + path;
} else {
//strip the http or https
String domain = Play.application().configuration().getString("page.url.base");
domain = domain.substring(domain.indexOf('/') + 2);
path = Protocols.NONE + domain + "/assets/" + path;
}
}
return path;
}
public static String asset(String path) {
//no need to include version on s3 assets
if (path.contains("static-assets-")) return path;
return assetWithoutVersion(path) + "?v=" + ASSETS_VERSION;
}
编辑2:
添加route.conf行(注意:我没有将路由器更新为&#34;注入&#34;版本)。这可能是一个问题吗?
GET /assets/*file controllers.Assets.at(path="/public", file: String)
答案 0 :(得分:0)
事实证明我必须改变两件事:
呈现的HTML必须是:
<script data-main="//local.prizeo.com:9000/assets/javascripts/main.js" src="/assets/lib/requirejs/require.js" type="text/javascript"></script>
注意“lib”前缀而不是javascripts
我还必须补充:
RjsKeys.paths += ("jsRoutes" -> ("/jsroutes" -> "empty:"))
到build.sbt
如果您知道它的作用,请发表评论 - 我在示例游戏项目中找到它并且没有找到任何文档。