Blue eyes

1,310 views

Published on

The author is managing editor of http://scalacourses.com, which offers self-paced online courses that teach Introductory and Intermediate Scala and Play Framework.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,310
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
31
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Blue eyes

  1. 1. @_JamesWard jamesward.com Intro to BlueEyes
  2. 2. What is BlueEyes? <ul><ul><li>Map HTTP requests to Scala handlers </li></ul></ul><ul><ul><ul><li>Determine Scala handler via a pattern tree </li></ul></ul></ul><ul><ul><ul><li>Patterns to match on include HTTP verb, content type, URL path </li></ul></ul></ul><ul><ul><ul><li>Patterns become partial functions </li></ul></ul></ul><ul><ul><li>Non-blocking end-to-end </li></ul></ul><ul><ul><li>Netty for HTTP </li></ul></ul><ul><ul><li>Versionable services </li></ul></ul>
  3. 3. <ul><ul><li>github.com/jamesward/helloblueeyes </li></ul></ul>
  4. 4. Run Locally <ul><ul><li>SBT Plugin for start script: </li></ul></ul><ul><ul><li>import com.typesafe.startscript.StartScriptPlugin </li></ul></ul><ul><ul><li>seq(StartScriptPlugin.startScriptForClassesSettings: _*) </li></ul></ul><ul><ul><li>$ sbt stage </li></ul></ul><ul><ul><li>$ target/start net.interdoodle.examples.AppServer </li></ul></ul>
  5. 5. Run on Heroku <ul><ul><li>Environment variable for port </li></ul></ul><ul><ul><li>trait EnvHttpServer extends HttpServer { self => </li></ul></ul><ul><ul><li>override def main(args: Array[String]) { </li></ul></ul><ul><ul><li>// build a config string </li></ul></ul><ul><ul><li>val configString = &quot;server.port = &quot; + </li></ul></ul><ul><ul><li>Properties.envOrElse(&quot;PORT&quot;, &quot;8080&quot;) + &quot;n&quot; + </li></ul></ul><ul><ul><li>&quot;server.sslEnable = &quot; + </li></ul></ul><ul><ul><li>Properties.envOrElse(&quot;SSL_ENABLE&quot;, &quot;false&quot;) </li></ul></ul><ul><ul><li>Create a Procfile </li></ul></ul><ul><ul><li>web: target/start net.interdoodle.example.AppServer </li></ul></ul>
  6. 6. Deploy on Heroku <ul><ul><li>$ git init </li></ul></ul><ul><ul><li>$ git add . </li></ul></ul><ul><ul><li>$ git commit -m init </li></ul></ul><ul><ul><li>$ heroku create -s cedar </li></ul></ul><ul><ul><li>$ git push heroku master </li></ul></ul>
  7. 7. Heroku Cool Stuff <ul><ul><li>$ heroku scale web=5 </li></ul></ul><ul><ul><li>$ heroku logs -t </li></ul></ul><ul><ul><li>$ heroku config </li></ul></ul><ul><ul><li>$ heroku releases </li></ul></ul><ul><ul><li>$ heroku addons </li></ul></ul>
  8. 8. <ul><ul><li>750 Free Dyno Hours </li></ul></ul><ul><ul><li>per application, per month </li></ul></ul>
  9. 9. <ul><ul><li>java.herokuapp.com </li></ul></ul>
  10. 10. Really Scalable Webapps <ul><ul><li>Client/Server all over again (UI/Data) </li></ul></ul><ul><ul><li>Stateless web tier </li></ul></ul><ul><ul><li>All UI state on the client </li></ul></ul><ul><ul><li>Static UI assets can easily be edge cached </li></ul></ul><ul><ul><li>Data is really hard to decentralize </li></ul></ul><ul><ul><li>UI on a CDN </li></ul></ul><ul><ul><li>Data on a CAP </li></ul></ul>
  11. 11. Multiple Hosts = Multiple Domains <ul><ul><li>Static content on: http://cdn.foo.com </li></ul></ul><ul><ul><li>App on: http://www.foo.com </li></ul></ul><ul><ul><li>Ruh Roh... XHR can't do crossdomain! </li></ul></ul><ul><ul><li>Options: </li></ul></ul><ul><ul><ul><li>JSONP </li></ul></ul></ul><ul><ul><ul><li>iframe hackery (not fun or clean) </li></ul></ul></ul><ul><ul><ul><li>Flash? </li></ul></ul></ul><ul><ul><ul><li>Browser x-origin opt-in... Someday. </li></ul></ul></ul><ul><ul><ul><li>Proxy server </li></ul></ul></ul><ul><ul><ul><li>Thin app wrapper </li></ul></ul></ul>
  12. 12. Thin App Wrapper <ul><ul><li>Load www.foo.com from app server </li></ul></ul><ul><ul><li>www.foo.com loads all static content (JavaScript, Images, HTML, CSS) from cdn.foo.com </li></ul></ul><ul><ul><li>JavaScript running in the context of www.foo.com make data requests back to www.foo.com </li></ul></ul>
  13. 13. Running Locally <ul><ul><li>Option 1) Netty HttpStaticFileServer serves static files over HTTP </li></ul></ul><ul><ul><li>Option 2) Whatever HTTP server you want </li></ul></ul>
  14. 14. <ul><ul><li>HelloJsonServices = JSON + jQuery </li></ul></ul><ul><ul><li>HelloMongoServices = JSON + jQuery + MongoDB </li></ul></ul>Examples
  15. 15. App on Heroku <ul><ul><li>$ heroku create -s cedar </li></ul></ul><ul><ul><li>$ git push heroku master </li></ul></ul>Static Content on AWS CloudFront <ul><ul><li>Copy src/main/webapp to S3 Bucket </li></ul></ul><ul><ul><li>Set permissions </li></ul></ul><ul><ul><li>Create CloudFront distribution </li></ul></ul>

×