-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
38 lines (30 loc) · 797 Bytes
/
app.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
class App
include SimpleRouter::DSL
extend Helpers
get '/healthcheck' do
respond 204
end
get '/auth' do
respond 200, body: { 'api_key' => 123 }
end
post '/auth/:id' do |id|
respond 201, body: { 'logged_in' => true, 'user_id' => id.to_i }
end
get '/profile' do
respond 200, body: file('profile.json')
end
get '/greet' do
respond 200, type: :html, body: file('greet.html')
end
def call(env)
request = Rack::Request.new(env)
verb = request.request_method.downcase.to_sym
path = Rack::Utils.unescape(request.path_info)
route = self.class.routes.match(verb, path)
if route.nil?
[404, { 'Content-Type' => 'text/plain' }, ['Not found']]
else
route.action.call(*route.values.push(request.params))
end
end
end