|
1 | 1 | Rails.application.routes.draw do
|
2 | 2 | # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
3 | 3 |
|
4 |
| - get "json", to: JsonController.action(:index) |
| 4 | + JsonApp = if defined?(Falcon) || defined?(Puma) || defined?(Agoo) |
| 5 | + ->(env) do |
| 6 | + [200, |
| 7 | + { |
| 8 | + 'Server' => 'Rails', |
| 9 | + 'Content-Type' => 'application/json', |
| 10 | + 'Date' => Time.now.httpdate, |
| 11 | + }, |
| 12 | + [{ 'message' => 'Hello, World!' }.to_json]] |
| 13 | + end |
| 14 | + else |
| 15 | + ->(env) do |
| 16 | + [200, |
| 17 | + { |
| 18 | + 'Server' => 'Rails', |
| 19 | + 'Content-Type' => 'application/json' |
| 20 | + }, |
| 21 | + [{ 'message' => 'Hello, World!' }.to_json]] |
| 22 | + end |
| 23 | + end |
| 24 | + |
| 25 | + PlaintextApp = if defined?(Falcon) || defined?(Puma) || defined?(Agoo) |
| 26 | + ->(env) do |
| 27 | + [200, |
| 28 | + { |
| 29 | + 'Server' => 'Rails', |
| 30 | + 'Content-Type' => 'text/plain', |
| 31 | + 'Date' => Time.now.httpdate |
| 32 | + }, |
| 33 | + ['Hello, World!']] |
| 34 | + end |
| 35 | + else |
| 36 | + ->(env) do |
| 37 | + [200, |
| 38 | + { |
| 39 | + 'Server' => 'Rails', |
| 40 | + 'Content-Type' => 'text/plain' |
| 41 | + }, |
| 42 | + ['Hello, World!']] |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + get "json", to: JsonApp |
5 | 47 | get "db", to: "hello_world#db"
|
6 | 48 | get "queries", to: "hello_world#query"
|
7 | 49 | get "fortunes", to: "hello_world#fortune"
|
8 | 50 | get "updates", to: "hello_world#update"
|
9 |
| - get "plaintext", to: ->(env) do |
10 |
| - [200, |
11 |
| - { |
12 |
| - 'Content-Type' => 'text/plain', |
13 |
| - 'Date' => Time.now.httpdate, |
14 |
| - 'Server' => 'Rails' |
15 |
| - }, |
16 |
| - ['Hello, World!']] |
17 |
| - end |
| 51 | + get "plaintext", to: PlaintextApp |
18 | 52 | get "cached", to: "hello_world#cached_query"
|
19 | 53 | end
|
0 commit comments