Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use Middleman Heroku buildpack to pre-compile site

* This should pre-build/pre-compile HTML and assets.
* See: https://github.com/indirect/middleman-heroku-static-app

Signed-off-by: Alex Coles <alex@alexbcoles.com>
  • Loading branch information...
commit c09a98d7f4f0197c38ac36eacf30612f7e3627bc 1 parent 939d16a
@myabc myabc authored
Showing with 43 additions and 3 deletions.
  1. +41 −3 config.ru
  2. +2 −0  config/heroku.yml
View
44 config.ru
@@ -1,6 +1,44 @@
# encoding: UTF-8
-require 'bundler/setup'
-require 'middleman'
+# Modified version of TryStatic, from rack-contrib
+# https://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/try_static.rb
-run Middleman.server
+# Serve static files under a `build` directory:
+# - `/` will try to serve your `build/index.html` file
+# - `/foo` will try to serve `build/foo` or `build/foo.html` in that order
+# - missing files will try to serve build/404.html or a tiny default 404 page
+
+
+module Rack
+
+ class TryStatic
+
+ def initialize(app, options)
+ @app = app
+ @try = ['', *options.delete(:try)]
+ @static = ::Rack::Static.new(lambda { [404, {}, []] }, options)
+ end
+
+ def call(env)
+ orig_path = env['PATH_INFO']
+ found = nil
+ @try.each do |path|
+ resp = @static.call(env.merge!({'PATH_INFO' => orig_path + path}))
+ break if 404 != resp[0] && found = resp
+ end
+ found or @app.call(env.merge!('PATH_INFO' => orig_path))
+ end
+ end
+end
+
+use Rack::TryStatic, :root => "build", :urls => %w[/], :try => ['.html', 'index.html', '/index.html']
+
+# Run your own Rack app here or use this one to serve 404 messages:
+run lambda{ |env|
+ not_found_page = File.expand_path("../build/404.html", __FILE__)
+ if File.exist?(not_found_page)
+ [ 404, { 'Content-Type' => 'text/html'}, [File.read(not_found_page)] ]
+ else
+ [ 404, { 'Content-Type' => 'text/html' }, ['404 - page not found'] ]
+ end
+}
View
2  config/heroku.yml
@@ -22,9 +22,11 @@ production:
app: eurucamp2012
config: &default
BUNDLE_WITHOUT: "development:test"
+ BUILDPACK_URL: http://github.com/indirect/heroku-buildpack-middleman.git
staging:
stack: cedar
app: eurucamp-dev
config: &default
BUNDLE_WITHOUT: "development:test"
+ BUILDPACK_URL: http://github.com/indirect/heroku-buildpack-middleman.git
Please sign in to comment.
Something went wrong with that request. Please try again.