Asset mapping outside public folder on Play framework

后端 未结 4 1205
悲哀的现实
悲哀的现实 2021-01-18 20:26

We have huge list of images that we need to store in an external path.. i.e outside of play application folder.

How can we make it available to play as an asset so i

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-18 20:30

    In the interests of completeness, I've experienced this problem many times and there has been no sufficient answer for it.

    Typically nginx would face the outside world and reverse-proxy back into the application server. You do not want to serve files straight from Play especially if you're building paths yourself which may present security risks. Let the experts handle static files, ie nginx.

    Play Framework supports sbt-native-packager's "dist" directory which will attach any files in there right inside the distribution ZIP package [1]. Here is the documentation for that:

    dist    → Arbitrary files to be included in your projects distribution
    

    For use cases such as controlled downloads use nginx's X-Accel where via a response header you tell nginx what file to send back to the client.


    TLDR: use nginx for what it's made for, use Play for what it's made for.

提交回复
热议问题