play-java-react-seed icon indicating copy to clipboard operation
play-java-react-seed copied to clipboard

Serving files on deployment server

Open yanlinaung30 opened this issue 6 years ago • 3 comments

Thanks for sharing the play & react integration source codes. I have a few problems on deployment in production mode. Could you consider how to solve the issue of my used case?

  • Back-end needs to download some images file from a server.
  • Front-end serves the files downloaded.
  • It works perfectly on development mode run by sbt run.
  • Deployment on production is done by sbt dist, unzip target/universal/xxxx.zip, cd xxx, ./bin/xxx Dplay.http.secret.key=lqkejrnjnjfajsdjfajhsdfhjasdf -Dconfig.file=/home/ubuntu/code/xxx/conf/application.conf -Dhttp.port=8080
  • Downloaded files are under xxx/public/images/
  • Front-end cannot serve the downloaded images file.
  • What I should need to change the config or controller to serve the file under xxx/public/images folder? Thank you.

yanlinaung30 avatar Dec 17 '18 02:12 yanlinaung30

@yanlinaung30 all the contents in public directory is directly exposed via this seed (mechanism used to server forntend source). Check the frontend asset traffic via browser dev tools network tab and use a similar kind of relative paths to access contents in public dir.

Make sure all downloaded images are dynamically added to the public dir.

yohangz avatar Dec 17 '18 17:12 yohangz

@yohangz Thanks for your reply. public dir means Root/public or Root/xxxSNAPSHOT/public or Root/ui/public. I have tried all public dirs by copy & paste image files to all public folders. Unfortunately it does not work...

yanlinaung30 avatar Dec 18 '18 03:12 yanlinaung30

When you build the play project artifact all static frontend assets generated by react codebase build is copied to public directory prior to play build and bundled in jar files generated.

Thus, if you are planing to dynamically retrieve and serve images via play framework you better keep the images in some other directory and implement a separate route to retrieve and server those.

yohangz avatar Dec 18 '18 10:12 yohangz