Skip to content
This repository has been archived by the owner on Jul 17, 2018. It is now read-only.

Server Ember App Out of Redis #4

Merged
merged 5 commits into from
Nov 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
HOST: lvh.me
DEVISE_SECRET: devise_secret
SECRET_TOKEN: caste_secret_token
TUMBLR_KEY: tumblr_key
ASSET_HOST=http://localhost:7000
INSTAGRAM_CLIENT_ID=instagram-client-id
RACK_ENV=development
TUMBLR_KEY=tumblr-key
TUMBLR_SECRET: tumblr_secret

NEW_RELIC_APP_NAME: caste
NEW_RELIC_LICENSE_KEY: new_relic_key

S3_BUCKET: s3_bucket
S3_ACCESS_KEY_ID: s3_access_key_id
S3_SECRET_ACCESS_KEY: s3_secret_access_key

WEB_CONCURRENCY: 1
WEB_CONCURRENCY=1
WEB_TIMEOUT: 30

INSTAGRAM_USER_ID: 12345
INSTAGRAM_CLIENT_ID: instagram_client_id
INSTAGRAM_CLIENT_SECRET: instagram_client_secret
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ gem 'paperclip'
gem 'rack-cors', require: 'rack/cors'
gem 'rack-timeout'
gem 'rails', '>= 4.0.1'
gem 'rails_serve_static_assets'
gem 'rails-assets-lodash'
gem 'rails-assets-moment'
gem 'rich', github: 'bastiaanterhorst/rich'
gem 'roman-numerals'
gem 'recipient_interceptor'
gem 'redis'
gem 'sass-rails'
gem 'tumblr_client'
gem 'uglifier'
Expand Down Expand Up @@ -65,6 +67,7 @@ group :test do
end

group :staging, :production do
gem 'sprockets-redirect'
gem 'heroku_rails_deflate'
gem 'newrelic_rpm', '>= 3.6.7'
gem 'rails_12factor'
Expand Down
23 changes: 15 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ GEM
json (~> 1.4)
nokogiri (>= 1.4.4)
uuidtools (~> 2.1)
barber (0.4.2)
barber (0.5.0)
ember-source
execjs
handlebars-source
handlebars-source (>= 1.0.0.rc.4)
bcrypt (3.1.7)
better_errors (1.0.1)
coderay (>= 1.0.0)
Expand All @@ -88,7 +88,7 @@ GEM
sass (>= 3.2.0)
thor
builder (3.1.4)
chunky_png (1.2.9)
chunky_png (1.3.3)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.3)
Expand All @@ -105,7 +105,7 @@ GEM
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
compass-rails (1.1.2)
compass-rails (2.0.0)
compass (>= 0.12.2)
crack (0.4.1)
safe_yaml (~> 0.9.0)
Expand Down Expand Up @@ -133,13 +133,13 @@ GEM
activemodel
ember-data-source (1.0.0.beta.11)
ember-source
ember-rails (0.14.1)
ember-rails (0.15.0)
active_model_serializers
barber (>= 0.4.1)
ember-data-source
ember-source
ember-data-source (>= 1.0.0.beta.5)
ember-source (>= 1.1.0)
execjs (>= 1.2)
handlebars-source
handlebars-source (> 1.0.0)
jquery-rails (>= 1.0.17)
railties (>= 3.1)
ember-source (1.8.0)
Expand Down Expand Up @@ -257,6 +257,7 @@ GEM
polyamorous (~> 1.0.0)
recipient_interceptor (0.1.2)
mail
redis (3.1.0)
responders (1.0.0)
railties (>= 3.2, < 5)
roman-numerals (0.3.0)
Expand Down Expand Up @@ -300,6 +301,9 @@ GEM
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (~> 2.8)
sprockets-redirect (0.2.0)
activesupport (>= 3.1.0)
rack
teaspoon (0.7.9)
railties (>= 3.2.5, < 5)
thor (0.18.1)
Expand Down Expand Up @@ -373,7 +377,9 @@ DEPENDENCIES
rails-assets-lodash
rails-assets-moment
rails_12factor
rails_serve_static_assets
recipient_interceptor
redis
rich!
roman-numerals
rspec-rails (>= 2.14)
Expand All @@ -383,6 +389,7 @@ DEPENDENCIES
spring
spring-commands-rspec
spring-commands-teaspoon
sprockets-redirect
teaspoon
timecop
tumblr_client
Expand Down
Binary file added app/assets/images/projects/magenta/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/projects/magenta/10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/projects/magenta/11.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/projects/magenta/13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/projects/magenta/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/projects/magenta/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/projects/magenta/4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/projects/magenta/5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/projects/magenta/7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/projects/magenta/8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/projects/magenta/9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions app/controllers/embers_controller.rb

This file was deleted.

20 changes: 20 additions & 0 deletions app/controllers/lookbooks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class LookbooksController < StaticController
def index
@lookbooks = build_lookbooks

render json: { lookbooks: @lookbooks }
end

def build_lookbooks
[{
id: "fall2014",
pages: [
{ url: image_url("lookbooks/fall2014/1.jpg") },
{ url: image_url("lookbooks/fall2014/2.jpg") },
{ url: image_url("lookbooks/fall2014/3.jpg") },
{ url: image_url("lookbooks/fall2014/4.jpg") },
{ url: image_url("lookbooks/fall2014/5.jpg") },
]
}]
end
end
66 changes: 63 additions & 3 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,67 @@
class ProjectsController < InheritedResources::Base
class ProjectsController < StaticController
def index
@projects = Project.all
@projects = find_projects

render json: @projects, serializer: CachedCollectionSerializer
render json: { projects: @projects }
end

private

def find_projects
[{
id: 1,
numeral: "I",
slug: "the-philadelphia-experiment",
pages: [
{ url: image_url("projects/the-philadelphia-experiment/1.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/2.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/3.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/4.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/5.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/6.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/7.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/8.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/9.jpg") },
{ url: image_url("projects/the-philadelphia-experiment/10.jpg") },
{ url: vimeo_url(61014435), video: true },
{ url: image_url("projects/the-philadelphia-experiment/12.jpg") },
]
}, {
id: 2,
numeral: "II",
slug: "zachary-armstrong",
pages: [
{ url: image_url("projects/zachary-armstrong/1.jpg") },
{ url: image_url("projects/zachary-armstrong/2.jpg") },
{ url: image_url("projects/zachary-armstrong/3.jpg") },
{ url: image_url("projects/zachary-armstrong/4.jpg") },
{ url: image_url("projects/zachary-armstrong/5.jpg") },
{ url: image_url("projects/zachary-armstrong/6.jpg") },
{ url: image_url("projects/zachary-armstrong/7.jpg") },
{ url: image_url("projects/zachary-armstrong/8.jpg") },
{ url: image_url("projects/zachary-armstrong/9.jpg") },
{ url: vimeo_url(86785302), video: true },
{ url: image_url("projects/zachary-armstrong/11.jpg") },
]
}, {
id: 3,
numeral: "III",
slug: "magenta",
pages: [
{ url: image_url("projects/magenta/1.jpg") },
{ url: image_url("projects/magenta/2.jpg") },
{ url: image_url("projects/magenta/3.jpg") },
{ url: image_url("projects/magenta/4.jpg") },
{ url: image_url("projects/magenta/5.jpg") },
{ url: vimeo_url(90116548), video: true },
{ url: image_url("projects/magenta/7.jpg") },
{ url: image_url("projects/magenta/8.jpg") },
{ url: image_url("projects/magenta/9.jpg") },
{ url: image_url("projects/magenta/10.jpg") },
{ url: image_url("projects/magenta/11.jpg") },
{ url: vimeo_url(93339618), video: true },
{ url: image_url("projects/magenta/13.jpg") },
]
}]
end
end
46 changes: 46 additions & 0 deletions app/controllers/redis_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class RedisController < ApplicationController
def index
with_redis do |redis|
version = params[:version].presence || "current"

html_key = "index:#{version}"

html = redis.get(html_key)

raise ActionController::RoutingError, "#{html_key} not found" if html.blank?

insert_csrf_meta(html)

render text: html
end
end

private

def insert_csrf_meta(html)
html.insert(head_pos(html), render_to_string(inline: "<%= csrf_meta_tags %>"))
end

def head_pos(html)
head_open = html.index("<head")
html.index(">", head_open) + 1
end

def body_bottom_pos(html)
html.index("</body>")
end

def with_redis
uri = URI.parse(ENV["REDISTOGO_URL"])

redis = Redis.new(
host: uri.host,
port: uri.port,
password: uri.password
)

yield redis

redis.quit
end
end
7 changes: 0 additions & 7 deletions app/controllers/splashes_controller.rb

This file was deleted.

15 changes: 15 additions & 0 deletions app/controllers/static_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class StaticController < ApplicationController

protected

def image_url(name)
URI.join(
root_url,
self.class.helpers.asset_url(name),
).to_s
end

def vimeo_url(id)
"http://player.vimeo.com/video/#{id}?title=0&amp;byline=0&amp;portrait=0&amp;color=cfcfcf%22%20width=%22888"
end
end
36 changes: 36 additions & 0 deletions app/controllers/videos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class VideosController < StaticController
def index
@videos = find_videos

render json: { videos: @videos }
end

private

def find_videos
[{
id: 6,
url: vimeo_url(109002548),
},
{
id: 5,
url: vimeo_url(99653555),
},
{
id: 4,
url: vimeo_url(84338572),
},
{
id: 3,
url: vimeo_url(83601495),
},
{
id: 2,
url: vimeo_url(81305762),
},
{
id: 1,
url: vimeo_url(73152136),
}]
end
end
1 change: 0 additions & 1 deletion app/views/embers/index.html

This file was deleted.

5 changes: 4 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

module CasteServer
class Application < Rails::Application
config.middleware.use "Rack::Deflater"
config.middleware.insert_before "ActionDispatch::Static", "Rack::Cors" do
allow do
origins "*"
Expand All @@ -32,9 +33,11 @@ class Application < Rails::Application
end

%w[services].each do |loaded|
config.autoload_paths << File.join(Rails.root, 'app', loaded)
config.autoload_paths << Rails.root.join("app", loaded)
end

config.action_controller.asset_host = ENV.fetch("ASSET_HOST", "")

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
Expand Down
2 changes: 0 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
# Code is not reloaded between requests.
config.cache_classes = true

config.action_controller.asset_host = ENV.fetch("ASSET_HOST")

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers
# and those relying on copy on write to perform better.
Expand Down
2 changes: 0 additions & 2 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
# Code is not reloaded between requests.
config.cache_classes = true

config.action_controller.asset_host = ENV.fetch("ASSET_HOST")

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers
# and those relying on copy on write to perform better.
Expand Down
Loading