Skip to content

Instantly share code, notes, and snippets.

@KitaitiMakoto
Created April 11, 2015 16:54
Show Gist options
  • Save KitaitiMakoto/6de477f756f74948846e to your computer and use it in GitHub Desktop.
Save KitaitiMakoto/6de477f756f74948846e to your computer and use it in GitHub Desktop.
require 'pathname'
require 'sinatra'
require 'sass'
require 'babel/transpiler'
Sass.load_paths << File.expand_path('bower_components/bibi/bibi-dev/res/styles/src', __dir__)
configure do
set :app_file, File.expand_path('.')
end
not_found do
'Not Found'
end
before do
# headers 'Content-Security-Policy' => "script-src 'self'"
headers 'Access-Control-Allow-Origin' => '*'
headers 'X-Frame-Options' => 'ALLOWALL'
path = File.join(settings.app_file, clean_path_info(unescape(request.path_info)))
@path = Pathname(path)
halt 404 unless @path.file?
end
get '/src/*.js' do
content_type 'application/javascript'
Babel::Transpiler.transform(@path.read)['code']
end
get '/*.html' do
erb @path.read
end
get '/*' do
content_type mime_type(@path.extname)
@path.open
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment