Created
December 6, 2011 23:56
-
-
Save metaphox/1440687 to your computer and use it in GitHub Desktop.
a basic sinatra file for deploying on cloud foundry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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