Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add CDN

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

0 comments on commit 1f15b8c

Please sign in to comment.
Something went wrong with that request. Please try again.