Reputation: 104
I am trying to serve a static html file let's call it index.html
for all dynamic urls like /tachyon/someId
. This someId
is generated dynamically. I have tried multiple ways to do this but all failed. This is what all I have tried.
controllers.Assets.at(path="/public", file="index.html")
for GET url /tachyon/*someId
. This failed saying missing parameter someId.index.html
through render. This also failed since index.html
is not a scala.html
template.routes.Assets.at("index.html")
through controller. This also failed since I want to return Result
but the return type for the method is different.ok(routes.Assets.at("index.html")
through controller. This also failed saying not a valid Call for ok.It would be better if there is a way to do this through controller and returning Result
from method in task helper
class to task
since I am returning Promise<Result>
from method in task
class.
Upvotes: 1
Views: 291
Reputation: 104
I got it working. Not sure if it is the correct solution or not. I rendered the index.html
by converting it to a byte array and then using ok
to render using ByteArrayInputStream
. Something like this.
File file = Play.getFile("path to the file", Play.current());
byte[] byteArray = IOUtils.toByteArray(new FileInputStream(file));
return ok(new ByteArrayInputStream(byteArray)).as("text/html");
Let me know if there is any better way to do this without using scala templating.
Thanks
Upvotes: 0
Reputation: 2681
I think you can use Twirl to generate the page. Since you want a static html, you can ignore the parameter in the body.
so in routes, add:
GET /tachyon/*someId somecontroller.index(someId)
in the controller's index function, you can return
Ok(views.html.somepage(someId))
And you create a somepage.scala.html Twirl function in views folder, but do not use someId in the body.
Upvotes: 1