Skip to content

Instantly share code, notes, and snippets.

@metaphox
Created December 6, 2011 23:56
Show Gist options
  • Select an option

  • Save metaphox/1440687 to your computer and use it in GitHub Desktop.

Select an option

Save metaphox/1440687 to your computer and use it in GitHub Desktop.
a basic sinatra file for deploying on cloud foundry
require 'sinatra'
get(/.+/) do
send_sinatra_file(request.path) {404}
end
not_found do
send_sinatra_file('404.html') {"Sorry, I cannot find #{request.path}"}
end
def send_sinatra_file(path, &missing_file_block)
file_path = File.join(File.dirname(__FILE__), 'public', path)
file_path = File.join(file_path, 'index.html') unless file_path =~ /\.[a-z]+$/i
File.exist?(file_path) ? send_file(file_path) : missing_file_block.call
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment