|
6 | 6 | configure do |
7 | 7 | mime_type :ico, 'image/x-icon' |
8 | 8 | set :static_cache_control, [:public, {:max_age => 604800 } ] |
| 9 | + #set :protection, :except => [:frame_options ] |
| 10 | + #disable :protection |
9 | 11 | end |
10 | 12 |
|
11 | 13 | error do |
|
16 | 18 | } ) |
17 | 19 | end |
18 | 20 |
|
19 | | -get '/status.json' do |
| 21 | + |
| 22 | +def get_or_post(path, opts={}, &block) |
| 23 | + get(path, opts, &block) |
| 24 | + post(path, opts, &block) |
| 25 | +end |
| 26 | + |
| 27 | +get_or_post '/status.json' do |
20 | 28 | jsonp( { |
21 | 29 | :success => true, |
22 | 30 | :message => "OK", |
|
30 | 38 | } ) |
31 | 39 | end |
32 | 40 |
|
33 | | -get '/test.json' do |
| 41 | +options '/test.json' do |
| 42 | + content_type :text |
| 43 | + headers \ |
| 44 | + 'Access-Control-Allow-Origin' => '*', |
| 45 | + 'Access-Control-Allow-Methods' => 'POST, GET', |
| 46 | + 'Access-Control-Max-Age' => '604800' |
| 47 | + body 'Yes, CORS is allowed!' |
| 48 | +end |
| 49 | + |
| 50 | +get_or_post '/test.json' do |
| 51 | + content_type :text |
| 52 | + headers \ |
| 53 | + 'Access-Control-Allow-Origin' => '*', |
| 54 | + 'Access-Control-Allow-Methods' => 'POST, GET', |
| 55 | + 'Access-Control-Max-Age' => '604800' |
| 56 | + |
34 | 57 | output = "" |
35 | 58 |
|
36 | 59 | str_regex = params[:regex] |
37 | 60 |
|
| 61 | + if str_regex.nil? || str_regex.length() == 0 |
| 62 | + return jsonp( |
| 63 | + :success => false, |
| 64 | + :message => "No regular expression to test" |
| 65 | + ) |
| 66 | + end |
| 67 | + |
| 68 | + if request.request_method == "get" |
| 69 | + form_data = request.query_string |
| 70 | + else |
| 71 | + form_data = request.env["rack.input"].read |
| 72 | + end |
| 73 | + |
38 | 74 | output << "<table class=\"table table-bordered table-striped\" style=\"width:auto;\">\n" |
39 | 75 |
|
40 | 76 | output << "\t<tr>\n" |
|
51 | 87 | output << "</td>\n" |
52 | 88 |
|
53 | 89 | options = 0 |
54 | | - str_options = request_params_multi(request.query_string)["option"] |
| 90 | + str_options = request_params_multi(form_data)[:option] |
55 | 91 | if str_options |
56 | 92 | if str_options.include?("comment") |
57 | 93 | options += Regexp::EXTENDED |
|
110 | 146 | output << "\t</tr>\n" |
111 | 147 | end |
112 | 148 |
|
| 149 | + # when ruby1.9 |
113 | 150 | #names = regex.names |
114 | 151 | #if names |
115 | 152 | # output << "\t<tr>\n" |
|
132 | 169 | output << "\t\t<th>match()</th>" |
133 | 170 | output << "\t</tr>\n" |
134 | 171 |
|
135 | | - inputs = request_params_multi(request.query_string)["input"] |
136 | | - |
137 | | - print inputs |
| 172 | + inputs = request_params_multi(form_data)["input"] |
138 | 173 |
|
139 | 174 | if not inputs |
140 | 175 | output << "\t<tr>\n" |
|
201 | 236 |
|
202 | 237 | output << "</table>\n" |
203 | 238 |
|
204 | | - content_type :text |
205 | 239 | jsonp( { |
206 | | - :debug => inputs, |
207 | 240 | :success => true, |
208 | 241 | :message => "OK", |
209 | 242 | :html => output, |
|
0 commit comments