4

ellou' Players

I need to crate custom CDN-like solution for small app purposes and wonder what is the best way to serving files directly with Play, but not placed under the public directory of the application? I need to gain access to FTP-upload folder.

Let's say that my app is run from /home/myaccount/playapps/app201 folder and is available at http://somedomain.tld address. I have also a common FTP account with folder pointing to /home/myaccount/ftp_upload.

What is the best way to serve file /home/myaccount/ftp_upload/folder_1/sub_2/file.txt as http://somedomain.tld/ftp_upload/folder_1/sub_2/file.txt (without any checks and restrictions)?

  • One option is to use HTTP server and set separate host or alias for ftp folder , but I would like to avoid using additional servers on some nodes (ref: if you're looking for server solution check the sample config).
  • Second is writing Application.serve(String filepath) action + route, but I don't need any additional actions before serving files. Is that make sense to use this approach?

Is there other option available?

(this question is also available at Google Groups)

Community
  • 1
  • 1
biesior
  • 55,576
  • 10
  • 125
  • 182
  • 1
    May I ask for some details? Part of the usefulness of a CDN -- at least in my opinion -- is that your requests don't contain cookies, because it's filling up unnecessary bandwidth. Is that part of the solution you wish for, e.g. serving dynamic requests from `www.example.com` and static requests (CDN) from `cdn.example.com` (or a whole different TLD)? Also, are most of your requests static (CDN) or dynamic? Maybe you have a rough percentage. It could also help to know if your main static dataset is small, say 90% of static requests are for at most a few GB of data. – Carsten Jun 13 '12 at 22:35
  • @Carsten, thx for response. I want to place large media files and other `fully public` stuff apart of app's structure, because I don't need access control for it. The App in this case holds paths and metadata - and of corse renders front-end. My goal can be easily demonstrated with use a front-end http server and alias for some folder [described here]( http://stackoverflow.com/a/10884297/1066240) , but I want to avoid use of the HTTP server. On the other hand I think that I just also can deploy app at port 80 and some lightweight server to catch the static requests.(will be more...) – biesior Jun 14 '12 at 18:40
  • @Caresten: (...more :)) I just realised (thanks to you) that serving these data from other domain will prevent cookie sending, which can be also good point for performance boost. – biesior Jun 14 '12 at 18:43

1 Answers1

2

If your Play folder and FTP folder are on the same host, you can use the public assets. From the documentation:

Note, if you define asset mappings outside “public,” you’ll need to tell sbt about it, e.g. if you want:

GET  /assets/*file               controllers.Assets.at("/public", file)
GET  /liabilities/*file          controllers.Assets.at("/foo", file)

you should add this to the project settings in project/Build.scala

// Add your own project settings here
playAssetsDirectories <+= baseDirectory / "foo"

I did not test it, but it's worth a try :-)

biesior
  • 55,576
  • 10
  • 125
  • 182
ndeverge
  • 21,378
  • 4
  • 56
  • 85
  • nico_ekito: thx for your answer, but unfortunately can't get it to work. I will try still, will let you know in case of any progress. – biesior May 28 '12 at 21:35
  • 7
    Wouldn't this require your own controller as the Assets controller copies and compiles all assets up front, i.e. the file must exist when you start Play? If you upload the file later it doesn't work. – nylund Sep 11 '12 at 12:08