I've got my Play app running:
http://localhost:9000
Nginx is proxy passing it to this url:
http://localhost/Demo/
I have a problem with static assets though. For instance, this asset in html template
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
is going to
http://localhost/assets/stylesheets/main.css
and obviously results in not being found. If I change it to this (add /Demo in front of the url):
<link rel="stylesheet" media="screen" href="/[email protected]("stylesheets/main.css")">
it will now correctly go to this url:
http://localhost/Demo/assets/stylesheets/main.css
My question is: how can I add this /Demo to all my static assets without hard codding it into my templates? I prefer to solve this using Play's routing and limit changes done to nginx conf.
I've tried adding a url prefix into application.conf like this
application.context="/Demo"
but that affected all urls not only the static ones, so not a solution. Any thoughts?
My stack: Play Framework 2.2.1 / Scala 2.10.3 / Java 8 64bit / Nginx 1.4.3 / Ubuntu 13.10 64bit
UPDATE: SOLUTION Thanks to @biesior for providing the Java version, I've converted it to scala:
package core
import controllers.routes
object Assets {
def at(path: String): String = {
"/Demo" + routes.Assets.at(path)
}
}
GET /Demo/assets/*file Assets.at("public", file)and read the official documentation? - Akos Krivachy/Demoto routes results in all assets 404ing. The only way it works if I append it in templates. - CaballeroGET /Demo/assets/*file controllers.Assets.at(path="/public", file). Meaning my pages had:<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">and resulted in:<link rel="stylesheet" media="screen" href="/Demo/assets/stylesheets/main.css">- Akos Krivachy/Demoor not (no change), but that is not the issue. I need it to work under Nginx and it does work if I edit the template URLs - all I want is one place to do this that's all. - Caballero