Gleeb
Gleeb

Reputation: 11289

how to server html pages with play

Hi I would like to serve my index.html page from the controller. and i do not want it to be a view, i want it to be a pure html file i have no need for plays template engine.

Consider the following:

Route: GET / controllers.MainApp.index

And the route implementation is:

def index = Action { implicit request =>
   if (AuthenticatedAction.isAuthenticated) {
      Ok(controllers.Assets.at(path="/public/", file="index.html"))     
    }    
     else Redirect(controllers.routes.Authentication.login())  }

I get the following error:

Cannot write an instance of play.api.mvc.Action[play.api.mvc.AnyContent] to HTTP response. Try to define a Writeable[play.api.mvc.Action[play.api.mvc.AnyContent]]

Is there any way to serve an html page like that?

A possible solution is to do something like that:

route: GET /*file controllers.Assets.versioned(path="/public", file: Asset)

and then return from the controller:

Redirect("/index.html")

Which gives me a url path which i don't want:

http://localhost:9000/index.html#/

Thanks

Upvotes: 1

Views: 460

Answers (1)

Matthias Berndt
Matthias Berndt

Reputation: 4587

I think the solution is to return

controllers.Assets.at(path="/public/", file="index.html")

rather than

Ok(controllers.Assets.at(path="/public/", file="index.html"))

The at method already returns a Result, so you don't need to use Ok here.

Upvotes: 1

Related Questions