History

Merge pull request #1480 from ojeytonwilliams/feat/cloudflare

Oliver Eyton-Williams committed 5 years ago

Commit 324ad132 parents f984f76 8eee6126 files · +34 −42Browse files

Unified · Split

6 files
  1. assets/javascripts/app/config.coffee.erb +1 −1
  2. lib/app.rb +3 −7
  3. lib/tasks/docs.thor +13 −17
  4. public/opensearch.xml +2 −2
  5. views/index.erb +12 −12
  6. views/other.erb +3 −3
assets/javascripts/app/config.coffee.erb+1−1
@@ -12,7 +12,7 @@ app.config = · 11 unmodified lines
12 sentry_dsn: '<%= App.sentry_dsn %>'12 sentry_dsn: '<%= App.sentry_dsn %>'
13 version: <%= Time.now.to_i %>13 version: <%= Time.now.to_i %>
14 release: <%= Time.now.utc.httpdate.to_json %>14 release: <%= Time.now.utc.httpdate.to_json %>
15 mathml_stylesheet: '<%= App.cdn_origin %>/mathml.css'15 mathml_stylesheet: '/mathml.css'
16 favicon_spritesheet: '<%= image_path('sprites/docs.png') %>'16 favicon_spritesheet: '<%= image_path('sprites/docs.png') %>'
17 service_worker_path: '/service-worker.js'17 service_worker_path: '/service-worker.js'
18 service_worker_enabled: <%= App.environment == :production || ENV['ENABLE_SERVICE_WORKER'] == 'true' %>18 service_worker_enabled: <%= App.environment == :production || ENV['ENABLE_SERVICE_WORKER'] == 'true' %>
lib/app.rb+3−7
@@ -20,8 +20,6 @@ class App < Sinatra::Application · 19 unmodified lines
20 set :root, Pathname.new(File.expand_path('../..', __FILE__))20 set :root, Pathname.new(File.expand_path('../..', __FILE__))
21 set :sprockets, Sprockets::Environment.new(root)21 set :sprockets, Sprockets::Environment.new(root)
22 22
23 set :cdn_origin, ''
24
25 set :assets_prefix, 'assets'23 set :assets_prefix, 'assets'
26 set :assets_path, File.join(public_folder, assets_prefix)24 set :assets_path, File.join(public_folder, assets_prefix)
27 set :assets_manifest_path, File.join(assets_path, 'manifest.json')25 set :assets_manifest_path, File.join(assets_path, 'manifest.json')
@@ -75,9 +73,8 @@ class App < Sinatra::Application · 47 unmodified lines
75 73
76 configure :production do74 configure :production do
77 set :static, false75 set :static, false
78 set :cdn_origin, 'https://cdn.devdocs.io'76 set :docs_origin, '//documents.devdocs.io'
79 set :docs_origin, '//docs.devdocs.io'77 set :csp, "default-src 'self' *; script-src 'self' 'nonce-devdocs' https://www.google-analytics.com https://secure.gaug.es https://*.jquery.com; font-src 'none'; style-src 'self' 'unsafe-inline' *; img-src 'self' * data:;"
80 set :csp, "default-src 'self' *; script-src 'self' 'nonce-devdocs' https://cdn.devdocs.io https://www.google-analytics.com https://secure.gaug.es https://*.jquery.com; font-src 'none'; style-src 'self' 'unsafe-inline' *; img-src 'self' * data:;"
81 78
82 use Rack::ConditionalGet79 use Rack::ConditionalGet
83 use Rack::ETag80 use Rack::ETag
@@ -102,7 +99,6 @@ class App < Sinatra::Application · 18 unmodified lines
102 99
103 Sprockets::Helpers.configure do |config|100 Sprockets::Helpers.configure do |config|
104 config.digest = true101 config.digest = true
105 config.asset_host = 'cdn.devdocs.io'
106 config.manifest = Sprockets::Manifest.new(sprockets, assets_manifest_path)102 config.manifest = Sprockets::Manifest.new(sprockets, assets_manifest_path)
107 end103 end
108 end104 end
@@ -202,7 +198,7 @@ class App < Sinatra::Application · 93 unmodified lines
202 198
203 def service_worker_asset_urls199 def service_worker_asset_urls
204 @@service_worker_asset_urls ||= [200 @@service_worker_asset_urls ||= [
205 javascript_path('application', asset_host: false),201 javascript_path('application'),
206 stylesheet_path('application'),202 stylesheet_path('application'),
207 image_path('sprites/docs.png'),203 image_path('sprites/docs.png'),
208 image_path('sprites/docs@2x.png'),204 image_path('sprites/docs@2x.png'),
lib/tasks/docs.thor+13−17
@@ -191,27 +191,23 @@ class DocsCLI < Thor · 190 unmodified lines
191 puts '[S3] Begin syncing.'191 puts '[S3] Begin syncing.'
192 docs.each do |doc|192 docs.each do |doc|
193 puts "[S3] Syncing #{doc.path}..."193 puts "[S3] Syncing #{doc.path}..."
194 cmd = "aws s3 sync #{File.join(Docs.store_path, doc.path)} s3://devdocs-assets/#{doc.path} --delete --profile devdocs"194 cmd = "aws s3 sync #{File.join(Docs.store_path, doc.path)} s3://devdocs-documents/#{doc.path} --delete --profile devdocs"
195 cmd << ' --dryrun' if options[:dryrun]195 cmd << ' --dryrun' if options[:dryrun]
196 system(cmd)196 system(cmd)
197 end197 end
198 puts '[S3] Done syncing.'198 puts '[S3] Done syncing.'
199 199
200 # Upload packages to dl.devdocs.io (used by the "thor docs:download" command)200 # Upload packages to downloads.devdocs.io (used by the "thor docs:download" command)
201 puts '[MaxCDN] Begin uploading.'201 puts '[S3 bundle] Begin uploading.'
202 Net::SFTP.start('ftp.devdocs-dl.devdocs.netdna-cdn.com', ENV['DEVDOCS_DL_USERNAME'], password: ENV['DEVDOCS_DL_PASSWORD']) do |sftp|202
203 docs.each do |doc|203 docs.each do |doc|
204 filename = "#{doc.path}.tar.gz"204 filename = "#{doc.path}.tar.gz"
205 print "[MaxCDN] Uploading #{filename}..."205 puts "[S3 bundle] Uploading #{filename}..."
206 if options[:dryrun]206 cmd = "aws s3 cp #{File.join(Docs.store_path, filename)} s3://devdocs-downloads/#{filename} --profile devdocs"
207 print "\n"207 cmd << ' --dryrun' if options[:dryrun]
208 else208 system(cmd)
209 sftp.upload! File.join(Docs.store_path, filename), File.join('', 'public_html', filename)
210 print " OK\n"
211 end
212 end
213 end209 end
214 puts '[MaxCDN] Done uploading.'210 puts '[S3 bundle] Done uploading.'
215 end211 end
216 212
217 desc 'commit', '[private]'213 desc 'commit', '[private]'
@@ -244,7 +240,7 @@ class DocsCLI < Thor · 26 unmodified lines
244 FileUtils.mkpath(dir)240 FileUtils.mkpath(dir)
245 241
246 ['index.json', 'meta.json'].each do |filename|242 ['index.json', 'meta.json'].each do |filename|
247 json = "https://docs.devdocs.io/#{doc.path}/#{filename}?#{time}"243 json = "https://documents.devdocs.io/#{doc.path}/#{filename}?#{time}"
248 begin244 begin
249 open(json) do |file|245 open(json) do |file|
250 mutex.synchronize do246 mutex.synchronize do
@@ -341,7 +337,7 @@ class DocsCLI < Thor · 90 unmodified lines
341 337
342 def download_doc(doc)338 def download_doc(doc)
343 target_path = File.join(Docs.store_path, doc.path)339 target_path = File.join(Docs.store_path, doc.path)
344 open "http://dl.devdocs.io/#{doc.path}.tar.gz" do |file|340 open "https://downloads.devdocs.io/#{doc.path}.tar.gz" do |file|
345 FileUtils.mkpath(target_path)341 FileUtils.mkpath(target_path)
346 file.close342 file.close
347 tar = UnixUtils.gunzip(file.path)343 tar = UnixUtils.gunzip(file.path)
public/opensearch.xml+2−2
@@ -4,8 +4,8 @@ · 3 unmodified lines
4 <Description>Search API documentation</Description>4 <Description>Search API documentation</Description>
5 <Tags>devdocs</Tags>5 <Tags>devdocs</Tags>
6 <Url type="text/html" method="get" template="https://devdocs.io/#q={searchTerms}"/>6 <Url type="text/html" method="get" template="https://devdocs.io/#q={searchTerms}"/>
7 <Image height="16" width="16" type="image/vnd.microsoft.icon">https://cdn.devdocs.io/favicon.ico</Image>7 <Image height="16" width="16" type="image/vnd.microsoft.icon">https://devdocs.io/favicon.ico</Image>
8 <Image height="64" width="64" type="image/x-icon">https://cdn.devdocs.io/images/icon-64.png</Image>8 <Image height="64" width="64" type="image/x-icon">https://devdocs.io/images/icon-64.png</Image>
9 <InputEncoding>UTF-8</InputEncoding>9 <InputEncoding>UTF-8</InputEncoding>
10 <moz:SearchForm>https://devdocs.io</moz:SearchForm>10 <moz:SearchForm>https://devdocs.io</moz:SearchForm>
11 <Url type="application/opensearchdescription+xml" rel="self" template="https://devdocs.io/opensearch.xml"/>11 <Url type="application/opensearchdescription+xml" rel="self" template="https://devdocs.io/opensearch.xml"/>
views/index.erb+12−12
@@ -9,7 +9,7 @@ · 8 unmodified lines
9 <meta property="og:description" content="Fast, offline, and free documentation browser for developers. Search 100+ docs in one web app including HTML, CSS, JavaScript, PHP, Ruby, Python, Go, C, C++, and many more.">9 <meta property="og:description" content="Fast, offline, and free documentation browser for developers. Search 100+ docs in one web app including HTML, CSS, JavaScript, PHP, Ruby, Python, Go, C, C++, and many more.">
10 <meta property="og:type" content="website">10 <meta property="og:type" content="website">
11 <meta property="og:url" content="<%= canonical_origin %>">11 <meta property="og:url" content="<%= canonical_origin %>">
12 <meta property="og:image" content="<%= App.cdn_origin %>/images/icon-320.png">12 <meta property="og:image" content="/images/icon-320.png">
13 <meta name="apple-mobile-web-app-title" content="DevDocs">13 <meta name="apple-mobile-web-app-title" content="DevDocs">
14 <meta name="apple-mobile-web-app-capable" content="yes">14 <meta name="apple-mobile-web-app-capable" content="yes">
15 <meta name="apple-mobile-web-app-status-bar-style" content="black">15 <meta name="apple-mobile-web-app-status-bar-style" content="black">
@@ -21,22 +21,22 @@ · 5 unmodified lines
21 <link rel="manifest" href="/manifest.json">21 <link rel="manifest" href="/manifest.json">
22 <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="DevDocs Search">22 <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="DevDocs Search">
23 <link rel="alternate" href="<%= canonical_origin %>/feed" title="DevDocs" type="application/atom+xml">23 <link rel="alternate" href="<%= canonical_origin %>/feed" title="DevDocs" type="application/atom+xml">
24 <link rel="icon" type="image/x-icon" href="<%= App.cdn_origin %>/favicon.ico">24 <link rel="icon" type="image/x-icon" href="/favicon.ico">
25 <link rel="fluid-icon" href="<%= App.cdn_origin %>/images/fluid-icon.png" title="DevDocs">25 <link rel="fluid-icon" href="/images/fluid-icon.png" title="DevDocs">
26 <link rel="apple-touch-icon" sizes="72x72" href="<%= App.cdn_origin %>/images/apple-icon-72.png">26 <link rel="apple-touch-icon" sizes="72x72" href="/images/apple-icon-72.png">
27 <link rel="apple-touch-icon" sizes="76x76" href="<%= App.cdn_origin %>/images/apple-icon-76.png">27 <link rel="apple-touch-icon" sizes="76x76" href="/images/apple-icon-76.png">
28 <link rel="apple-touch-icon" sizes="114x114" href="<%= App.cdn_origin %>/images/apple-icon-114.png">28 <link rel="apple-touch-icon" sizes="114x114" href="/images/apple-icon-114.png">
29 <link rel="apple-touch-icon" sizes="120x120" href="<%= App.cdn_origin %>/images/apple-icon-120.png">29 <link rel="apple-touch-icon" sizes="120x120" href="/images/apple-icon-120.png">
30 <link rel="apple-touch-icon" sizes="144x144" href="<%= App.cdn_origin %>/images/apple-icon-144.png">30 <link rel="apple-touch-icon" sizes="144x144" href="/images/apple-icon-144.png">
31 <link rel="apple-touch-icon" sizes="152x152" href="<%= App.cdn_origin %>/images/apple-icon-152.png">31 <link rel="apple-touch-icon" sizes="152x152" href="/images/apple-icon-152.png">
32 <link rel="apple-touch-icon" sizes="160x160" href="<%= App.cdn_origin %>/images/apple-icon-160.png">32 <link rel="apple-touch-icon" sizes="160x160" href="/images/apple-icon-160.png">
33 <link rel="mask-icon" href="<%= App.cdn_origin %>/images/webkit-mask-icon.svg" color="#398df0">33 <link rel="mask-icon" href="/images/webkit-mask-icon.svg" color="#398df0">
34 <%= stylesheet_tag 'application' %>34 <%= stylesheet_tag 'application' %>
35</head>35</head>
36<body>36<body>
37<noscript class="_fail">DevDocs requires JavaScript to run.</noscript>37<noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
38<%= erb :app -%>38<%= erb :app -%>
39<%= javascript_tag 'application', asset_host: false %>39<%= javascript_tag 'application' %>
40<%= javascript_tag 'docs' %><% unless App.production? %>40<%= javascript_tag 'docs' %><% unless App.production? %>
41<%= javascript_tag 'debug' %><% end %>41<%= javascript_tag 'debug' %><% end %>
42</body>42</body>
views/other.erb+3−3
@@ -6,18 +6,18 @@ · 5 unmodified lines
6 <% if doc_index_page? %><meta name="description" content="<%= @doc['name'] %> <%= @doc['release'] %> API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more."><% else %><meta name="robots" content="noindex"><% end %>6 <% if doc_index_page? %><meta name="description" content="<%= @doc['name'] %> <%= @doc['release'] %> API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more."><% else %><meta name="robots" content="noindex"><% end %>
7 <meta name="format-detection" content="telephone=no">7 <meta name="format-detection" content="telephone=no">
8 <meta name="theme-color" content="#eee">8 <meta name="theme-color" content="#eee">
9 <meta property="og:image" content="<%= App.cdn_origin %>/images/icon-320.png">9 <meta property="og:image" content="/images/icon-320.png">
10 <title>DevDocs<%= " &mdash; #{@doc['full_name']} documentation" if doc_index_page? %></title>10 <title>DevDocs<%= " &mdash; #{@doc['full_name']} documentation" if doc_index_page? %></title>
11 <link rel="canonical" href="<%= canonical_origin %><%= request.path %>">11 <link rel="canonical" href="<%= canonical_origin %><%= request.path %>">
12 <link rel="manifest" href="/manifest.json">12 <link rel="manifest" href="/manifest.json">
13 <link rel="icon" type="image/x-icon" href="<%= App.cdn_origin %>/favicon.ico">13 <link rel="icon" type="image/x-icon" href="/favicon.ico">
14 <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="Search DevDocs">14 <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="Search DevDocs">
15 <%= stylesheet_tag 'application' %>15 <%= stylesheet_tag 'application' %>
16</head>16</head>
17<body data-doc="<%= CGI::escape_html @doc.to_json %>">17<body data-doc="<%= CGI::escape_html @doc.to_json %>">
18<noscript class="_fail">DevDocs requires JavaScript to run.</noscript>18<noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
19<%= erb :app -%>19<%= erb :app -%>
20<%= javascript_tag 'application', asset_host: false %><% unless App.production? %>20<%= javascript_tag 'application' %><% unless App.production? %>
21<%= javascript_tag 'debug' %><% end %>21<%= javascript_tag 'debug' %><% end %>
22</body>22</body>
23</html>23</html>