SlideShare a Scribd company logo
Deploying a
location-aware EmberJS app
Ben Limmer
EmberJS Denver Meetup
5/27/2015
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
deployment can be
scary
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
!==
Dev/Staging Production
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
data/servers can differ
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
data/servers can differ
db sharding
mini/uglification
caching
latency
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
us testing
>
users testing
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
dev/qa/stakeholder testing in prod
>
users testing in prod
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
enter ember-cli-deploy
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
– Michael Klein
“Lightning Fast Deployments of Ember-CLI
Apps”
LevelbossMike
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
– Ben Limmer
“Easy, Lightning Fast, Sleep-Better-at-Night,
Deployments of Ember-CLI Apps”
blimmer
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
how does it work?
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
“abc123”: “<html>...</html>”
what’s current?
contents of abc123
example.org
“current”: “abc123”
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
“def456”: “<html>...</html>”
app-hash.css, app-hash.js, ...
what’s current?
contents of abc123
“abc123”: “<html>...</html>”
example.org
“current”: “abc123”
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
“def456”: “<html>...</html>”
what’s def456?
contents of def456
“abc123”: “<html>...</html>”
example.org/?
secret=def456
“current”: “abc123”
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
“def456”: “<html>...</html>”
what’s current?
contents of def456
“abc123”: “<html>...</html>”
example.org
“current”: “def456”
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
💩!
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
“def456”: “<html>...</html>”
what’s current?
contents of abc123
“abc123”: “<html>...</html>”
example.org
“current”: “abc123”
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
demo project
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
Español English
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
ip address mexican user
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
ember-cli-server-variables
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
Client Stack
• EmberJS 1.12
• ember-i18n
• ember-cli-deploy (redis + s3 adapters)
• ember-cli-server-variables
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
client code
ember-cli-server-variables
config/environment.js
1 module.exports = function(environment) {
2 var ENV = {
3 modulePrefix: 'location-aware-ember',
4
5 serverVariables: {
6 tagPrefix: 'var',
7 vars: ['country']
8 }
9 };
10
11 if (environment === 'development') {
12 ENV.serverVariables.defaults = {
13 'country': 'US'
14 };
15 }
16 }
session initialization
1 export default Ember.Service.extend({
2 serverVariables: Ember.inject.service(),
3
4 countryCode: 'US',
5
6 forceInitialization: function () {
7 const country = this.get('serverVariables.country');
8 if (country) {
9 this.set('countryCode', country);
10 }
11 }
12 });
app/services/session.js
app initialization
app/routes/application.js
1 export default Ember.Route.extend({
2 i18n: Ember.inject.service(),
3 session: Ember.inject.service(),
4
5 beforeModel: function () {
6 this.set(
7 'i18n.locale',
8 languageForCountryCode(this.get('session.countryCode'))
9 );
10 }
11 });
languageForCountryCode
app/utils/language-for-country-code.js
1 export default function languageForCountryCode(countryCode) {
2 switch(countryCode.toLowerCase()) {
3 case 'es':
4 case 'mx':
5 return 'es';
6 case 'gb':
7 case 'us':
8 return 'en';
9 default:
10 return 'en';
11 }
12 }
translations (en)
app/locales/en/translations.js
1 export default {
2 'home': {
3 'greeting': 'Hello!',
4 'secondaryGreeting': 'Thank you for visiting from
{{countryName}}.'
5 }
6 };
translations (es)
app/locales/es/translations.js
1 export default {
2 'home': {
3 'greeting': ‘¡Hola!',
4 'secondaryGreeting': 'Gracias por visitar desde
{{countryName}}.'
5 }
6 };
template
app/templates/index.hbs
1 <div class='row'>
2 <h2 class='text-center' id="greeting">
3 {{t 'home.greeting'}}
4 </h2>
5 </div>
6 <div class='row'>
7 <h4 class='text-center' id="secondary-greeting">
8 {{t 'home.secondaryGreeting' countryName=countryName}}
9 </h4>
10 </div>
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
demo
Server Stack
Hosting
• heroku
• heroku-redis
Server Tech
• express 4
• geoip-lite
• redis
• cheerio
• node-ember-cli-
deploy-redis
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
server code
server routing
index.js
1 app.get('/', function(req, res) {
2 nodeEmberCliDeployRedis.
3 fetchIndex(‘location-aware-ember’, req, client).
4 then(function (indexHtml) {
5 indexHtml = serverVarInjectHelper.
6 injectServerVariables(indexHtml, req);
7 res.status(200).send(indexHtml);
8 }).catch(function(err) {
9 res.status(500).send('Oh noes!n' + err.message);
10 });
11 });
inject server variables
lib/server-var-inject-helper.js
1 var injectServerVariables = function (htmlString, req) {
2 var $ = cheerio.load(htmlString);
3 $('meta[name=var-country]').
4 attr('content', locationHelper.getCountry(req));
5
6 return $.html();
7 };
geocode ip address
lib/location-helper.js
1 var getCountry = function (req) {
2 var ipAddr = req.headers["x-forwarded-for"];
3 if (ipAddr){
4 var list = ipAddr.split(",");
5 ipAddr = list[list.length-1];
6 } else {
7 ipAddr = req.connection.remoteAddress;
8 }
9
10 var geo = geoip.lookup(ipAddr);
11
12 if (geo && geo.country) {
13 return geo.country;
14 } else {
15 return 'US';
16 }
17 };
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
running in prod
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
feature request:
change locale in realtime
git diff
++app/templates/index.hbs
1 <div class='row language-chooser'>
2 <h6>{{t 'home.chooseLang'}}</h6>
3 <a id='set-en' {{action 'setLanguage' 'en'}}>EN</a>
4 <a id='set-es' {{action 'setLanguage' 'es'}}>ES</a>
5 </div>
git diff
++app/routes/application.js
1 export default Ember.Route.extend({
2 i18n: Ember.inject.service(),
3 ...
4 actions: {
5 setLanguage: function (locale) {
6 this.set('i18n.locale', locale);
7 }
8 }
9 });
deloyment config
config/deploy.js
1 module.exports = {
2 "production": {
3 buildEnv: "production",
4 store: {
5 host: 'ec2-107-22-167-67.compute-1.amazonaws.com',
6 port: 6929,
7 password: process.env.REDIS_PW,
8 },
9 assets: {
10 "type": "s3",
11 "accessKeyId": "AKIAIFM7MT2JTIHV6HBA",
12 "secretAccessKey": process.env.S3_SECRET_ACCESS_KEY,
13 "bucket": "location-aware-ember"
14 }
15 }
16 };
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
demo
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
thank you!
blimmer
l1m5
hello@benlimmer.com
ember.party
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
demo project code
• location-aware-ember
• location-aware-ember-server
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
demo project libs (client)
• ember-cli-deploy
• s3 adapter
• redis adapter
• ember-cli-server-variables
• ember-i18n
Ben LimmerEmberJS Meetup - 5/27/2015 ember.party
demo project libs (server)
• express js
• geoip-lite
• redis
• cheerio
• node-ember-cli-deploy-redis

More Related Content

What's hot (20)

PPTX
Introduction to es6
NexThoughts Technologies
 
PPTX
AngularJS Unit Testing
Prince Norin
 
PDF
PWA 與 Service Worker
Anna Su
 
PDF
Djangocon 2014 angular + django
Nina Zakharenko
 
PDF
Service Worker Presentation
Kyle Dorman
 
PDF
2011-02-03 LA RubyConf Rails3 TDD Workshop
Wolfram Arnold
 
PDF
Mini Rails Framework
Aviandri Rivai
 
PDF
Automated Testing with Ruby
Keith Pitty
 
PDF
Building an API with Django and Django REST Framework
Christopher Foresman
 
PDF
Cucumber Ru09 Web
Joseph Wilk
 
PDF
API Days Paris - Automatic Testing of (RESTful) API Documentation
Rouven Weßling
 
PDF
Cooking Up Drama
bridgetkromhout
 
PDF
Cooking Up Drama - ChefConf 2015
Chef
 
PDF
React Development with the MERN Stack
Troy Miles
 
PDF
Service workers
jungkees
 
PDF
Zenly - Reverse geocoding
CocoaHeads France
 
PDF
Server Side Swift
Jens Ravens
 
PDF
RSpec 2 Best practices
Andrea Reginato
 
PPTX
PowerShell: Automation for everyone
Gavin Barron
 
KEY
Psgi Plack Sfpm
som_nangia
 
Introduction to es6
NexThoughts Technologies
 
AngularJS Unit Testing
Prince Norin
 
PWA 與 Service Worker
Anna Su
 
Djangocon 2014 angular + django
Nina Zakharenko
 
Service Worker Presentation
Kyle Dorman
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
Wolfram Arnold
 
Mini Rails Framework
Aviandri Rivai
 
Automated Testing with Ruby
Keith Pitty
 
Building an API with Django and Django REST Framework
Christopher Foresman
 
Cucumber Ru09 Web
Joseph Wilk
 
API Days Paris - Automatic Testing of (RESTful) API Documentation
Rouven Weßling
 
Cooking Up Drama
bridgetkromhout
 
Cooking Up Drama - ChefConf 2015
Chef
 
React Development with the MERN Stack
Troy Miles
 
Service workers
jungkees
 
Zenly - Reverse geocoding
CocoaHeads France
 
Server Side Swift
Jens Ravens
 
RSpec 2 Best practices
Andrea Reginato
 
PowerShell: Automation for everyone
Gavin Barron
 
Psgi Plack Sfpm
som_nangia
 

Similar to Deploying a Location-Aware Ember Application (20)

KEY
fog or: How I Learned to Stop Worrying and Love the Cloud
Wesley Beary
 
KEY
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
Wesley Beary
 
KEY
Writing robust Node.js applications
Tom Croucher
 
PDF
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
崇之 清水
 
PDF
Node Boot Camp
Troy Miles
 
PPTX
Building Web Apps with Express
Aaron Stannard
 
PDF
Mock Servers - Fake All the Things!
Atlassian
 
KEY
Server side scripting smack down - Node.js vs PHP
Marc Gear
 
ODP
jBPM6 Updates
Kris Verlaenen
 
PDF
Node js introduction
Alex Su
 
PPTX
Intro to node and mongodb 1
Mohammad Qureshi
 
PDF
What's New In Laravel 5
Darren Craig
 
PPTX
REST API for your WP7 App
Agnius Paradnikas
 
ODP
Deep dive into jBPM6
Kris Verlaenen
 
PDF
Mасштабирование микросервисов на Go, Matt Heath (Hailo)
Ontico
 
PPTX
Building and Scaling Node.js Applications
Ohad Kravchick
 
PPT
Developing node-mdb: a Node.js - based clone of SimpleDB
Rob Tweed
 
PDF
Marrying angular rails
Volker Tietz
 
KEY
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Paulo Ragonha
 
PDF
NodeJS "Web en tiempo real"
Sebastián Gamboa
 
fog or: How I Learned to Stop Worrying and Love the Cloud
Wesley Beary
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
Wesley Beary
 
Writing robust Node.js applications
Tom Croucher
 
RESTful API を Chalice で紐解く 〜 Python Serverless Microframework for AWS 〜
崇之 清水
 
Node Boot Camp
Troy Miles
 
Building Web Apps with Express
Aaron Stannard
 
Mock Servers - Fake All the Things!
Atlassian
 
Server side scripting smack down - Node.js vs PHP
Marc Gear
 
jBPM6 Updates
Kris Verlaenen
 
Node js introduction
Alex Su
 
Intro to node and mongodb 1
Mohammad Qureshi
 
What's New In Laravel 5
Darren Craig
 
REST API for your WP7 App
Agnius Paradnikas
 
Deep dive into jBPM6
Kris Verlaenen
 
Mасштабирование микросервисов на Go, Matt Heath (Hailo)
Ontico
 
Building and Scaling Node.js Applications
Ohad Kravchick
 
Developing node-mdb: a Node.js - based clone of SimpleDB
Rob Tweed
 
Marrying angular rails
Volker Tietz
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Paulo Ragonha
 
NodeJS "Web en tiempo real"
Sebastián Gamboa
 
Ad

More from Ben Limmer (8)

PDF
Tips & Tricks for Being a Successful Tech Lead
Ben Limmer
 
PDF
1-Up Your Git Skills
Ben Limmer
 
PDF
Maximize your output (sans productivity shame)
Ben Limmer
 
PDF
[OLD] Understanding Github PR Merge Options (1up-ing your git skills part 2)
Ben Limmer
 
PDF
Upgrading Ember.js Apps
Ben Limmer
 
PDF
Fun with Ember 2.x Features
Ben Limmer
 
PDF
Building Realtime Apps with Ember.js and WebSockets
Ben Limmer
 
PDF
Building a Single Page Application using Ember.js ... for fun and profit
Ben Limmer
 
Tips & Tricks for Being a Successful Tech Lead
Ben Limmer
 
1-Up Your Git Skills
Ben Limmer
 
Maximize your output (sans productivity shame)
Ben Limmer
 
[OLD] Understanding Github PR Merge Options (1up-ing your git skills part 2)
Ben Limmer
 
Upgrading Ember.js Apps
Ben Limmer
 
Fun with Ember 2.x Features
Ben Limmer
 
Building Realtime Apps with Ember.js and WebSockets
Ben Limmer
 
Building a Single Page Application using Ember.js ... for fun and profit
Ben Limmer
 
Ad

Recently uploaded (20)

PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 

Deploying a Location-Aware Ember Application