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
1212 sentry_dsn: '<%= App.sentry_dsn %>'
1313 version: <%= Time.now.to_i %>
1414 release: <%= Time.now.utc.httpdate.to_json %>
15− mathml_stylesheet: '<%= App.cdn_origin %>/mathml.css'
15+ mathml_stylesheet: '/mathml.css'
1616 favicon_spritesheet: '<%= image_path('sprites/docs.png') %>'
1717 service_worker_path: '/service-worker.js'
1818 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
2020 set :root, Pathname.new(File.expand_path('../..', __FILE__))
2121 set :sprockets, Sprockets::Environment.new(root)
2222
23− set :cdn_origin, ''
24−
2523 set :assets_prefix, 'assets'
2624 set :assets_path, File.join(public_folder, assets_prefix)
2725 set :assets_manifest_path, File.join(assets_path, 'manifest.json')
@@ -75,9 +73,8 @@ class App < Sinatra::Application · 47 unmodified lines
7573
7674 configure :production do
7775 set :static, false
78− set :cdn_origin, 'https://cdn.devdocs.io'
79− set :docs_origin, '//docs.devdocs.io'
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:;"
76+ set :docs_origin, '//documents.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:;"
8178
8279 use Rack::ConditionalGet
8380 use Rack::ETag
@@ -102,7 +99,6 @@ class App < Sinatra::Application · 18 unmodified lines
10299
103100 Sprockets::Helpers.configure do |config|
104101 config.digest = true
105− config.asset_host = 'cdn.devdocs.io'
106102 config.manifest = Sprockets::Manifest.new(sprockets, assets_manifest_path)
107103 end
108104 end
@@ -202,7 +198,7 @@ class App < Sinatra::Application · 93 unmodified lines
202198
203199 def service_worker_asset_urls
204200 @@service_worker_asset_urls ||= [
205− javascript_path('application', asset_host: false),
201+ javascript_path('application'),
206202 stylesheet_path('application'),
207203 image_path('sprites/docs.png'),
208204 image_path('sprites/docs@2x.png'),
lib/tasks/docs.thor+13−17
@@ -191,27 +191,23 @@ class DocsCLI < Thor · 190 unmodified lines
191191 puts '[S3] Begin syncing.'
192192 docs.each do |doc|
193193 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"
195195 cmd << ' --dryrun' if options[:dryrun]
196196 system(cmd)
197197 end
198198 puts '[S3] Done syncing.'
199199
200− # Upload packages to dl.devdocs.io (used by the "thor docs:download" command)
201− puts '[MaxCDN] Begin uploading.'
202− Net::SFTP.start('ftp.devdocs-dl.devdocs.netdna-cdn.com', ENV['DEVDOCS_DL_USERNAME'], password: ENV['DEVDOCS_DL_PASSWORD']) do |sftp|
203− docs.each do |doc|
204− filename = "#{doc.path}.tar.gz"
205− print "[MaxCDN] Uploading #{filename}..."
206− if options[:dryrun]
207− print "\n"
208− else
209− sftp.upload! File.join(Docs.store_path, filename), File.join('', 'public_html', filename)
210− print " OK\n"
211− end
212− end
200+ # Upload packages to downloads.devdocs.io (used by the "thor docs:download" command)
201+ puts '[S3 bundle] Begin uploading.'
202+
203+ docs.each do |doc|
204+ filename = "#{doc.path}.tar.gz"
205+ puts "[S3 bundle] Uploading #{filename}..."
206+ cmd = "aws s3 cp #{File.join(Docs.store_path, filename)} s3://devdocs-downloads/#{filename} --profile devdocs"
207+ cmd << ' --dryrun' if options[:dryrun]
208+ system(cmd)
213209 end
214− puts '[MaxCDN] Done uploading.'
210+ puts '[S3 bundle] Done uploading.'
215211 end
216212
217213 desc 'commit', '[private]'
@@ -244,7 +240,7 @@ class DocsCLI < Thor · 26 unmodified lines
244240 FileUtils.mkpath(dir)
245241
246242 ['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}"
248244 begin
249245 open(json) do |file|
250246 mutex.synchronize do
@@ -341,7 +337,7 @@ class DocsCLI < Thor · 90 unmodified lines
341337
342338 def download_doc(doc)
343339 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|
345341 FileUtils.mkpath(target_path)
346342 file.close
347343 tar = UnixUtils.gunzip(file.path)
public/opensearch.xml+2−2
@@ -4,8 +4,8 @@ · 3 unmodified lines
44 <Description>Search API documentation</Description>
55 <Tags>devdocs</Tags>
66 <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>
8− <Image height="64" width="64" type="image/x-icon">https://cdn.devdocs.io/images/icon-64.png</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://devdocs.io/images/icon-64.png</Image>
99 <InputEncoding>UTF-8</InputEncoding>
1010 <moz:SearchForm>https://devdocs.io</moz:SearchForm>
1111 <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
99 <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.">
1010 <meta property="og:type" content="website">
1111 <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">
1313 <meta name="apple-mobile-web-app-title" content="DevDocs">
1414 <meta name="apple-mobile-web-app-capable" content="yes">
1515 <meta name="apple-mobile-web-app-status-bar-style" content="black">
@@ -21,22 +21,22 @@ · 5 unmodified lines
2121 <link rel="manifest" href="/manifest.json">
2222 <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="DevDocs Search">
2323 <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">
25− <link rel="fluid-icon" href="<%= App.cdn_origin %>/images/fluid-icon.png" title="DevDocs">
26− <link rel="apple-touch-icon" sizes="72x72" href="<%= App.cdn_origin %>/images/apple-icon-72.png">
27− <link rel="apple-touch-icon" sizes="76x76" href="<%= App.cdn_origin %>/images/apple-icon-76.png">
28− <link rel="apple-touch-icon" sizes="114x114" href="<%= App.cdn_origin %>/images/apple-icon-114.png">
29− <link rel="apple-touch-icon" sizes="120x120" href="<%= App.cdn_origin %>/images/apple-icon-120.png">
30− <link rel="apple-touch-icon" sizes="144x144" href="<%= App.cdn_origin %>/images/apple-icon-144.png">
31− <link rel="apple-touch-icon" sizes="152x152" href="<%= App.cdn_origin %>/images/apple-icon-152.png">
32− <link rel="apple-touch-icon" sizes="160x160" href="<%= App.cdn_origin %>/images/apple-icon-160.png">
33− <link rel="mask-icon" href="<%= App.cdn_origin %>/images/webkit-mask-icon.svg" color="#398df0">
24+ <link rel="icon" type="image/x-icon" href="/favicon.ico">
25+ <link rel="fluid-icon" href="/images/fluid-icon.png" title="DevDocs">
26+ <link rel="apple-touch-icon" sizes="72x72" href="/images/apple-icon-72.png">
27+ <link rel="apple-touch-icon" sizes="76x76" href="/images/apple-icon-76.png">
28+ <link rel="apple-touch-icon" sizes="114x114" href="/images/apple-icon-114.png">
29+ <link rel="apple-touch-icon" sizes="120x120" href="/images/apple-icon-120.png">
30+ <link rel="apple-touch-icon" sizes="144x144" href="/images/apple-icon-144.png">
31+ <link rel="apple-touch-icon" sizes="152x152" href="/images/apple-icon-152.png">
32+ <link rel="apple-touch-icon" sizes="160x160" href="/images/apple-icon-160.png">
33+ <link rel="mask-icon" href="/images/webkit-mask-icon.svg" color="#398df0">
3434 <%= stylesheet_tag 'application' %>
3535 </head>
3636 <body>
3737 <noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
3838 <%= erb :app -%>
39−<%= javascript_tag 'application', asset_host: false %>
39+<%= javascript_tag 'application' %>
4040 <%= javascript_tag 'docs' %><% unless App.production? %>
4141 <%= javascript_tag 'debug' %><% end %>
4242 </body>
views/other.erb+3−3
@@ -6,18 +6,18 @@ · 5 unmodified lines
66 <% 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 %>
77 <meta name="format-detection" content="telephone=no">
88 <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">
1010 <title>DevDocs<%= " &mdash; #{@doc['full_name']} documentation" if doc_index_page? %></title>
1111 <link rel="canonical" href="<%= canonical_origin %><%= request.path %>">
1212 <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">
1414 <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="Search DevDocs">
1515 <%= stylesheet_tag 'application' %>
1616 </head>
1717 <body data-doc="<%= CGI::escape_html @doc.to_json %>">
1818 <noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
1919 <%= erb :app -%>
20−<%= javascript_tag 'application', asset_host: false %><% unless App.production? %>
20+<%= javascript_tag 'application' %><% unless App.production? %>
2121 <%= javascript_tag 'debug' %><% end %>
2222 </body>
2323 </html>