Hosting static HTML in a Play! app on CloudFront

a 夏天 提交于 2019-12-08 02:01:59

问题


I have a (high-traffic) chunk of my website that is entirely static. All the site's URLs are relative, so right now it all works if I just point my browser to http://gj232j2j213.cloudfront.net/blah.

I'd like to host the entire thing (not just images and css, but the HTML too) on Cloudfont (or some other CDN).

Ideally, I could put something like:

GET    /static/    staticDir:http://gj232j2j213.cloudfront.net/blah

in my routes file. That way my URLs would look like www.mydomain.com/static/main.html, and I wouldn't have to bounce the user to a different subdomain as they moved back and forth between my static and non-static URLs.

Any ideas? Am I misguided?


回答1:


I've used the following in my conf/routes file to do this:

# Map static resources from the /app/public folder to the /public path
#{if play.Play.mode.isDev()}
    GET     /public/                        staticDir:public
#{/}
#{else}
    GET     d2iu8jbjgczc8x.cloudfront.net/public  staticDir:public
    GET     /public/                              staticDir:public
#{/}

Then you just reference the static assets the normal way and the URLs will use the CloudFront server (in Prod mode).




回答2:


Could never get this to work in Play 2.x.

GET     /public/      staticDir:public

What worked for me is something like this.

GET  /somefile.html   controllers.Assets.at(path="/public", file="somefile.html")


来源:https://stackoverflow.com/questions/10524285/hosting-static-html-in-a-play-app-on-cloudfront

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!