@@ -27,7 +27,21 @@ module Web
2727 ##
2828 # Roda app serving RSS feeds via html2rss
2929 class App < Roda
30- CONTENT_TYPE_RSS = 'application/xml'
30+ FALLBACK_HTML = <<~HTML
31+ <!DOCTYPE html>
32+ < html >
33+ < head >
34+ < title > html2rss-web</ title >
35+ < meta name ="viewport " content ="width=device-width,initial-scale=1 ">
36+ < meta name ="robots " content ="noindex,nofollow ">
37+ </ head >
38+ < body >
39+ < h1 > html2rss-web</ h1 >
40+ < p > Convert websites to RSS feeds</ p >
41+ < p > API available at < code > /api/</ code > </ p >
42+ </ body >
43+ </ html >
44+ HTML
3145
3246 def self . development? = EnvironmentValidator . development?
3347 def development? = self . class . development?
@@ -47,13 +61,18 @@ def development? = self.class.development?
4761 plugin :content_security_policy do |csp |
4862 csp . default_src :none
4963 csp . style_src :self , "'unsafe-inline'"
50- csp . script_src :self , "'unsafe-inline'"
64+ csp . script_src :self
5165 csp . connect_src :self
5266 csp . img_src :self
53- csp . font_src :self , 'data:'
67+ csp . font_src :self
5468 csp . form_action :self
5569 csp . base_uri :none
56- csp . frame_ancestors development? ? [ 'http://localhost:*' , 'https://localhost:*' ] : :none
70+ if development?
71+ csp . frame_ancestors 'http://localhost:*' , 'https://localhost:*' ,
72+ 'http://127.0.0.1:*' , 'https://127.0.0.1:*'
73+ else
74+ csp . frame_ancestors :none
75+ end
5776 csp . frame_src :self
5877 csp . object_src :none
5978 csp . media_src :none
@@ -85,11 +104,9 @@ def development? = self.class.development?
85104 plugin :error_handler do |error |
86105 next exception_page ( error ) if development?
87106
88- # Simple error handling for production
89- http_status = error . respond_to? ( :status ) ? error . status : 500
90107 error_code = error . respond_to? ( :code ) ? error . code : 'INTERNAL_SERVER_ERROR'
91108
92- response . status = http_status
109+ response . status = error . respond_to? ( :status ) ? error . status : 500
93110
94111 if request . path . start_with? ( '/api/v1/' )
95112 response [ 'Content-Type' ] = 'application/json'
@@ -124,25 +141,7 @@ def handle_feed_generation(router, feed_name)
124141 def render_index_page ( router )
125142 index_path = 'public/frontend/index.html'
126143 router . response [ 'Content-Type' ] = 'text/html'
127- File . exist? ( index_path ) ? File . read ( index_path ) : fallback_html
128- end
129-
130- def fallback_html
131- <<~HTML
132- <!DOCTYPE html>
133- < html >
134- < head >
135- < title > html2rss-web</ title >
136- < meta name ="viewport " content ="width=device-width,initial-scale=1 ">
137- < meta name ="robots " content ="noindex,nofollow ">
138- </ head >
139- < body >
140- < h1 > html2rss-web</ h1 >
141- < p > Convert websites to RSS feeds</ p >
142- < p > API available at < code > /api/</ code > </ p >
143- </ body >
144- </ html >
145- HTML
144+ File . exist? ( index_path ) ? File . read ( index_path ) : FALLBACK_HTML
146145 end
147146 end
148147 end
0 commit comments