【问题标题】:play framework: no assets in production mode播放框架:生产模式下没有资产
【发布时间】:2012-11-23 09:07:53
【问题描述】:

我有一个奇怪的问题。我有一个用 Play 编写的应用程序!框架 2.0.4。它使用一些公共资产(css/images/javascript)。当我在开发模式下运行它时一切都很好:

blus@vmblus:~/svn/blus> play
[info] Loading project definition from /home/blus/svn/blus/project/project
[info] Loading project definition from /home/blus/svn/blus/project
[info] Set current project to blus (in build file:/home/blus/svn/blus/)
       _            _
 _ __ | | __ _ _  _| |
| '_ \| |/ _' | || |_|
|  __/|_|\____|\__ (_)
|_|            |__/

play! 2.0.4, http://www.playframework.org

> Type "help play" or "license" for more information.
> Type "exit" or use Ctrl+D to leave this console.

[blus] $ run

--- (Running the application from SBT, auto-reloading is enabled) ---

[info] play - Listening for HTTP on port 9000...

(Server started, use Ctrl+D to stop and go back to the console...)

资产在浏览器中加载没有任何问题。但是当我想在生产模式下运行相同的应用程序(不复制,不移动,只是一样)时,资产消失了:

[blus] $ start 9000

(Starting server. Type Ctrl+D to exit logs, the server will remain in background)

Play server process ID is 6845
[info] play - Application started (Prod)
[info] play - Listening for HTTP on port 9000...

萤火虫表演:

"NetworkError: 404 Not Found - http://vmblus:9000/assets/stylesheets/main.css"

没有找到所有需要的资产。这怎么可能?我能做些什么来解决这个问题?

这是我conf/routes的一部分:

GET /assets/*file controllers.ExternalAssets.at(path="public", file)

这就是我在视图中调用资产的方式:

<link rel="stylesheet" media="screen" href="@routes.ExternalAssets.at("stylesheets/main.css")">

我看到了this question,但我的路径没有//

【问题讨论】:

    标签: playframework-2.0 development-environment assets production-environment


    【解决方案1】:

    您使用的是controllers.ExternalAssets.at 而不是controllers.Assets.at

    这很可能是原因。

    【讨论】:

    • 我必须承认,它与controllers.Assets.at 一起工作,但我不得不切换,因为我想允许用户下载一些文件,正如this answer 所建议的那样。我猜正确的解决方案是结合这两种方法,对吧?你能解释一下为什么会这样吗?或者至少提供任何链接?
    • 我刚刚检查过,一切似乎都可以使用controllers.Assets.at,甚至是文件下载。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2018-03-25
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    相关资源
    最近更新 更多