Felipe
Felipe

Reputation: 11887

Loading an arbitrary file in the Play Framework 2 (Scala)

I'm trying to serve an AngularJS application using the Play 2 Framework for Scala and I think I understand, in general, how the routes and the templates work.

In order to serve the angularJS files (which should NOT be available for users publicly), I'm currently placing them under /public and then creating routes for them.

I would like to have a little more flexibility over where my angular js files are. I'm aware of the assets.at() method that creates an action for this purpose but I cannot serve files that live anywhere other than /public, no matter what I do. I will need to intercept the call and only serve the javascript file if the user has the correct permissions.

So I think my question is whether this is the right approach for what I have in mind (selective serving of angular JS files - depending upon permissions and so on ) and whether I'm stuck with having to place my angularJS app under /public - is it not possible to serve files from anywhere else?

Upvotes: 1

Views: 229

Answers (2)

acjay
acjay

Reputation: 36491

You can wrap the built-in Assets controller. Instead of using the router to invoke it directly, as is the default, invoke your own Action, and use Action composition to wrap it with your authorization logic.

Upvotes: 1

Lionel Port
Lionel Port

Reputation: 3542

I'd like to see what is not working for you. You should be allowed to have assets served from multiple paths

routes.conf

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

Then in your templates.

<script src="@routes.Assets.at("/public", "test.js")"></script>
<script src="@routes.Assets.at("/secure", "test.js")"></script>

Upvotes: 0

Related Questions