Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add CDN

  • Loading branch information...
commit 1f15b8c06a5b7b298b111f263f3c26197fbee096 1 parent 73a977a
@jamesward authored
View
3  app/models/S3Photo.java
@@ -6,6 +6,7 @@
import org.imgscalr.Scalr;
import play.Logger;
import play.db.ebean.Model;
+import play.Play;
import utils.S3Blob;
import javax.imageio.ImageIO;
@@ -28,7 +29,7 @@
public String key;
public URL getUrl() throws MalformedURLException {
- return new URL("https://s3.amazonaws.com/" + bucket + "/" + key);
+ return new URL(Play.application().configuration().getString("s3url") + "/" + key);
}
public S3Photo() {
View
19 app/utils/CDN.scala
@@ -0,0 +1,19 @@
+package utils
+
+import play.api.Play.current
+import play.api.mvc.Call
+import play.api.Play
+
+object CDN {
+
+ def apply(call: Call): String = {
+
+ Play.maybeApplication.flatMap { app =>
+ app.configuration.getString("cdnurl")
+ }.map { cdnurl =>
+ cdnurl.format(call.url)
+ }.getOrElse(call.url)
+
+ }
+
+}
View
8 app/views/main.scala.html
@@ -4,9 +4,9 @@
<html>
<head>
<title>@title</title>
- <link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
- <link rel='stylesheet' href='@routes.WebJarAssets.at(WebJarAssets.locate("css/bootstrap.min.css"))'>
- <script type='text/javascript' src='@routes.WebJarAssets.at(WebJarAssets.locate("jquery.min.js"))'></script>
+ <link rel="shortcut icon" type="image/png" href="@utils.CDN(routes.Assets.at("images/favicon.png"))">
+ <link rel='stylesheet' href='@utils.CDN(routes.WebJarAssets.at(WebJarAssets.locate("css/bootstrap.min.css")))'>
+ <script type='text/javascript' src='@utils.CDN(routes.WebJarAssets.at(WebJarAssets.locate("jquery.min.js")))'></script>
<style type="text/css">
body {
margin-top: 50px;
@@ -57,7 +57,7 @@
@bodyContent
</div>
- <script type='text/javascript' src='@routes.WebJarAssets.at(WebJarAssets.locate("bootstrap.min.js"))'></script>
+ <script type='text/javascript' src='@utils.CDN(routes.WebJarAssets.at(WebJarAssets.locate("bootstrap.min.js")))'></script>
</body>
</html>
View
4 conf/application.conf
@@ -22,6 +22,8 @@ application.langs="en"
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
+# db.default.driver=org.h2.Driver
+# db.default.url="jdbc:h2:mem:play"
db.default.driver=org.postgresql.Driver
db.default.url="postgres://hikeubertracks:password@localhost/hikeubertracks"
db.default.partitionCount=1
@@ -63,3 +65,5 @@ aws.secret.key=${?AWS_SECRET_KEY}
aws.s3.bucket=com.ubertracks.hike.dev
smtp.host=mock
+
+s3url="http://d22b1laoj19yrb.cloudfront.net"
View
3  conf/prod.conf
@@ -6,6 +6,9 @@ db.default.driver=org.postgresql.Driver
db.default.url=${DATABASE_URL}
applyEvolutions.default=true
+cdnurl="http://d3z1287k477c6.cloudfront.net%s"
+s3url="http://d3eqr9j8hjgd1w.cloudfront.net"
+
smtp.host=smtp.sendgrid.net
smtp.port=587
smtp.ssl=true
View
2  project/Build.scala
@@ -12,7 +12,7 @@ object ApplicationBuild extends Build {
javaCore,
javaJdbc,
javaEbean,
- "org.webjars" % "webjars-play" % "2.1.0",
+ "org.webjars" % "webjars-play" % "2.1.0-1",
"org.webjars" % "bootstrap" % "2.3.1",
"postgresql" % "postgresql" % "9.1-901-1.jdbc4",
"rome" % "rome" % "1.0",
Please sign in to comment.
Something went wrong with that request. Please try again.