-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
executable file
·53 lines (42 loc) · 1.53 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'sinatra/base'
class ActivityPub < Sinatra::Application
@my_routes =
[
[:get, '/.well-known/host-meta/?', HostMetaRoute],
[:get, '/.well-known/webfinger/?', WebfingerRoute],
[:get, '/users/:username/outbox/?', OutboxRoute],
[:post, '/users/:username/outbox/?', CreateOutboxRoute],
[:get, '/users/:username/inbox/?', ReadInboxRoute],
[:post, '/users/:username/inbox/?', InboxRoute],
[:get, '/users/:username/?', AccountRoute],
[:get, '/users/:username/followers/?', FollowersRoute],
[:get, '/users/:username/following/?', FollowingRoute],
[:get, '/users/:username/collections/:id/?', CollectionRoute],
[:get, '/users/:username/activities/:id/?', ReadActivityRoute],
[:get, '/users/:username/:type/:id/?', ReadObjectRoute]
]
@my_routes.each do |meth, path, klass|
send(meth, path) do
formatted_request =
request.tap do |req|
req.params.merge!(params)
headers =
req
.env
.keys
.select { |k| k.start_with?('HTTP_') }
.each_with_object({}) do |key, hash|
header_name =
key
.downcase
.sub(/^http_./) { |foo| foo[-1].upcase }
.gsub(/_./) { |foo| "-#{foo[1].upcase}" }
hash[header_name] = req.env[key]
end
headers['Content-Type'] = req.env['CONTENT_TYPE']
req['headers'] = headers
end
klass.call(formatted_request)
end
end
end