1
votes

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?

2
What do you mean "...to serve the angularJS files (which should NOT be available for users publicly)"? - acjay
Sorry for the delay. I mean that we will actually refuse to serve some .js files if the current user has not enough clearance, even if it amounts to an error in the frontend. We cannot afford to serve the whole angular JS app in one go and have all functionalities available for all types (levels) of users. - Felipe

2 Answers

1
votes

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.

0
votes

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>