File tree Expand file tree Collapse file tree 2 files changed +4
-18
lines changed Expand file tree Collapse file tree 2 files changed +4
-18
lines changed Original file line number Diff line number Diff line change 2
2
require "ftw" # gem ftw
3
3
require "sinatra/base" # gem sinatra
4
4
require "optparse"
5
+ require "mime/type"
5
6
6
7
class Rack ::Handler ::FTW
7
8
alias_method :handle_connection_ , :handle_connection
@@ -41,15 +42,7 @@ def static_file
41
42
path = File . join ( docroot , *request . path_info . split ( "/" ) )
42
43
if File . exists? ( path )
43
44
ext = path . split ( "." ) . last
44
- case ext
45
- when "js" ; content_type "application/javascript"
46
- when "css" ; content_type "text/css"
47
- when "jpg" ; content_type "image/jpeg"
48
- when "jpeg" ; content_type "image/jpeg"
49
- when "png" ; content_type "image/png"
50
- when "gif" ; content_type "image/gif"
51
- end
52
-
45
+ content_type MIME ::Types . type_for ( ext ) . first . to_s
53
46
body File . new ( path , "r" ) . read
54
47
else
55
48
status 404
Original file line number Diff line number Diff line change 1
1
require "sinatra/base"
2
+ require "mime/type"
2
3
3
4
class LogStash ::Web ::Server < Sinatra ::Base
4
5
get '/js/*' do static_file end
@@ -15,15 +16,7 @@ def static_file
15
16
#p :static => path
16
17
if File . exists? ( path )
17
18
ext = path . split ( "." ) . last
18
- case ext
19
- when "js" ; content_type "application/javascript"
20
- when "css" ; content_type "text/css"
21
- when "jpg" ; content_type "image/jpeg"
22
- when "jpeg" ; content_type "image/jpeg"
23
- when "png" ; content_type "image/png"
24
- when "gif" ; content_type "image/gif"
25
- end
26
-
19
+ content_type MIME ::Types . type_for ( ext ) . first . to_s
27
20
body File . new ( path , "r" ) . read
28
21
else
29
22
status 404
You can’t perform that action at this time.
0 commit comments