forked from postrank-labs/goliath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrack_routes.rb
More file actions
executable file
·44 lines (36 loc) · 1.02 KB
/
Copy pathrack_routes.rb
File metadata and controls
executable file
·44 lines (36 loc) · 1.02 KB
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
43
44
#!/usr/bin/env ruby
$:<< '../lib' << 'lib'
require 'goliath'
# Example demonstrating how to have an API acting as a router.
# RackRoutes defines multiple uris and how to map them accordingly.
# Some of these routes are redirected to other Goliath API.
#
# The reason why only the last API is being used by the Goliath Server
# is because its name matches the filename.
# All the APIs are available but by default the server will use the one
# matching the file name.
# Our custom Goliath API
class HelloWorld < Goliath::API
def response(env)
[200, {}, "hello world!"]
end
end
class Bonjour < Goliath::API
def response(env)
[200, {}, "bonjour!"]
end
end
class RackRoutes < Goliath::API
map '/version' do
run Proc.new { |env| [200, {"Content-Type" => "text/html"}, ["Version 0.1"]] }
end
map "/hello_world" do
run HelloWorld.new
end
map "/bonjour" do
run Bonjour.new
end
map '/' do
run Proc.new { |env| [404, {"Content-Type" => "text/html"}, ["Try /version /hello_world or /bonjour"]] }
end
end