-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathapp.rb
104 lines (84 loc) · 2.65 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# frozen_string_literal: true
require 'roda'
require 'rack/cache'
require_relative 'roda/roda_plugins/basic_auth'
require 'html2rss'
require_relative 'app/ssrf_filter_strategy'
module Html2rss
module Web
##
# This app uses html2rss and serves the feeds via HTTP.
#
# It is built with [Roda](https://roda.jeremyevans.net/).
class App < Roda
CONTENT_TYPE_RSS = 'application/xml'
Html2rss::RequestService.register_strategy(:ssrf_filter, SsrfFilterStrategy)
Html2rss::RequestService.default_strategy_name = :ssrf_filter
Html2rss::RequestService.unregister_strategy(:faraday)
def self.development? = ENV['RACK_ENV'] == 'development'
opts[:check_dynamic_arity] = false
opts[:check_arity] = :warn
use Rack::Cache,
metastore: 'file:./tmp/rack-cache-meta',
entitystore: 'file:./tmp/rack-cache-body',
verbose: development?
plugin :content_security_policy do |csp|
csp.default_src :none
csp.style_src :self
csp.script_src :self
csp.connect_src :self
csp.img_src :self
csp.font_src :self, 'data:'
csp.form_action :self
csp.base_uri :none
csp.frame_ancestors :self
csp.frame_src :self
csp.block_all_mixed_content
end
plugin :default_headers,
'Content-Type' => 'text/html',
'X-Content-Type-Options' => 'nosniff',
'X-XSS-Protection' => '1; mode=block'
plugin :exception_page
plugin :error_handler do |error|
next exception_page(error) if development?
handle_error(error)
end
plugin :hash_branch_view_subdir
plugin :public
plugin :content_for
plugin :render, escape: true, layout: 'layout'
plugin :typecast_params
plugin :basic_auth
Dir['routes/**/*.rb'].each do |f|
if development?
Unreloader.require f
else
require_relative f
end
end
@show_backtrace = !ENV['CI'].to_s.empty? || development?
route do |r|
r.public
r.hash_branches('')
r.root { view 'index' }
r.get 'health_check.txt' do
handle_health_check
end
r.on String, String do |folder_name, config_name_with_ext|
handle_html2rss_configs(request, folder_name, config_name_with_ext)
end
r.on String do |config_name_with_ext|
handle_local_config_feeds(request, config_name_with_ext)
end
end
Dir['helpers/*.rb'].each do |f|
if development?
Unreloader.require f
else
require_relative f
end
end
end
end
end