-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathserver.rb
42 lines (36 loc) · 978 Bytes
/
server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'rubygems'
require 'sinatra'
require 'net/http'
require 'net/https'
get '/' do
headers 'Cache-Control' => 'public, max-age 43200'
haml :app
end
get '/demo' do
headers 'Cache-Control' => 'public, max-age 43200'
haml :demo
end
get '/css/:name.css' do |name|
begin
headers 'Cache-Control' => 'public, max-age 43200'
content_type 'text/css'
sass :"sass/#{name}"
rescue
#halt 404
end
end
get '/proxy' do
uri = URI.parse(params[:url])
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == "https"
image_response = nil
http.start {
image_response = http.request_get(uri.path)
}
content_type = image_response.response['Content-Type']
if ["image/png", "image/jpeg", "image/jpg", "image/gif"].include?(content_type) && image_response.body.length < 1000000
headers 'Cache-Control' => 'public, max-age 43200'
response.headers['Content-Type'] = content_type
image_response.body
end
end