[devdocsgjs/main: 1491/1867] fix: remove cdn entirely and rely on Cloudflare




commit c6264eb1bffa3b467c8aff460569b22f6dfa3dc5
Author: Oliver Eyton-Williams <ojeytonwilliams gmail com>
Date:   Thu Jan 21 10:25:51 2021 +0100

    fix: remove cdn entirely and rely on Cloudflare

 assets/javascripts/app/config.coffee.erb |  2 +-
 lib/app.rb                               |  8 ++------
 lib/tasks/docs.thor                      |  1 +
 public/opensearch.xml                    |  4 ++--
 views/index.erb                          | 24 ++++++++++++------------
 views/other.erb                          |  6 +++---
 6 files changed, 21 insertions(+), 24 deletions(-)
---
diff --git a/assets/javascripts/app/config.coffee.erb b/assets/javascripts/app/config.coffee.erb
index a822f7e2..97e91ace 100644
--- a/assets/javascripts/app/config.coffee.erb
+++ b/assets/javascripts/app/config.coffee.erb
@@ -12,7 +12,7 @@ app.config =
   sentry_dsn: '<%= App.sentry_dsn %>'
   version: <%= Time.now.to_i %>
   release: <%= Time.now.utc.httpdate.to_json %>
-  mathml_stylesheet: '<%= App.cdn_origin %>/mathml.css'
+  mathml_stylesheet: '/mathml.css'
   favicon_spritesheet: '<%= image_path('sprites/docs.png') %>'
   service_worker_path: '/service-worker.js'
   service_worker_enabled: <%= App.environment == :production || ENV['ENABLE_SERVICE_WORKER'] == 'true' %>
diff --git a/lib/app.rb b/lib/app.rb
index c1198f86..917d1a03 100644
--- a/lib/app.rb
+++ b/lib/app.rb
@@ -20,8 +20,6 @@ class App < Sinatra::Application
     set :root, Pathname.new(File.expand_path('../..', __FILE__))
     set :sprockets, Sprockets::Environment.new(root)
 
-    set :cdn_origin, ''
-
     set :assets_prefix, 'assets'
     set :assets_path, File.join(public_folder, assets_prefix)
     set :assets_manifest_path, File.join(assets_path, 'manifest.json')
@@ -75,9 +73,8 @@ class App < Sinatra::Application
 
   configure :production do
     set :static, false
-    set :cdn_origin, 'https://cdn.devdocs.io'
     set :docs_origin, '//docs.devdocs.io'
-    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:;"
+    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:;"
 
     use Rack::ConditionalGet
     use Rack::ETag
@@ -102,7 +99,6 @@ class App < Sinatra::Application
 
     Sprockets::Helpers.configure do |config|
       config.digest = true
-      config.asset_host = 'cdn.devdocs.io'
       config.manifest = Sprockets::Manifest.new(sprockets, assets_manifest_path)
     end
   end
@@ -202,7 +198,7 @@ class App < Sinatra::Application
 
     def service_worker_asset_urls
       @@service_worker_asset_urls ||= [
-        javascript_path('application', asset_host: false),
+        javascript_path('application'),
         stylesheet_path('application'),
         image_path('sprites/docs.png'),
         image_path('sprites/docs 2x png'),
diff --git a/lib/tasks/docs.thor b/lib/tasks/docs.thor
index 5ed3f5cf..4c41a1be 100644
--- a/lib/tasks/docs.thor
+++ b/lib/tasks/docs.thor
@@ -198,6 +198,7 @@ class DocsCLI < Thor
     puts '[S3] Done syncing.'
 
     # Upload packages to dl.devdocs.io (used by the "thor docs:download" command)
+    # TODO(MIGRATION): replace this with an S3 bucket upload.
     puts '[MaxCDN] Begin uploading.'
     Net::SFTP.start('ftp.devdocs-dl.devdocs.netdna-cdn.com', ENV['DEVDOCS_DL_USERNAME'], password: 
ENV['DEVDOCS_DL_PASSWORD']) do |sftp|
       docs.each do |doc|
diff --git a/public/opensearch.xml b/public/opensearch.xml
index 734c4249..9c78ffdb 100644
--- a/public/opensearch.xml
+++ b/public/opensearch.xml
@@ -4,8 +4,8 @@
   <Description>Search API documentation</Description>
   <Tags>devdocs</Tags>
   <Url type="text/html" method="get" template="https://devdocs.io/#q={searchTerms}"/>
-  <Image height="16" width="16" type="image/vnd.microsoft.icon">https://cdn.devdocs.io/favicon.ico</Image>
-  <Image height="64" width="64" type="image/x-icon">https://cdn.devdocs.io/images/icon-64.png</Image>
+  <Image height="16" width="16" type="image/vnd.microsoft.icon">https://devdocs.io/favicon.ico</Image>
+  <Image height="64" width="64" type="image/x-icon">https://devdocs.io/images/icon-64.png</Image>
   <InputEncoding>UTF-8</InputEncoding>
   <moz:SearchForm>https://devdocs.io</moz:SearchForm>
   <Url type="application/opensearchdescription+xml" rel="self" template="https://devdocs.io/opensearch.xml"/>
diff --git a/views/index.erb b/views/index.erb
index 4fb96153..ce0cb887 100644
--- a/views/index.erb
+++ b/views/index.erb
@@ -9,7 +9,7 @@
   <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.">
   <meta property="og:type" content="website">
   <meta property="og:url" content="<%= canonical_origin %>">
-  <meta property="og:image" content="<%= App.cdn_origin %>/images/icon-320.png">
+  <meta property="og:image" content="/images/icon-320.png">
   <meta name="apple-mobile-web-app-title" content="DevDocs">
   <meta name="apple-mobile-web-app-capable" content="yes">
   <meta name="apple-mobile-web-app-status-bar-style" content="black">
@@ -21,22 +21,22 @@
   <link rel="manifest" href="/manifest.json">
   <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="DevDocs 
Search">
   <link rel="alternate" href="<%= canonical_origin %>/feed" title="DevDocs" type="application/atom+xml">
-  <link rel="icon" type="image/x-icon" href="<%= App.cdn_origin %>/favicon.ico">
-  <link rel="fluid-icon" href="<%= App.cdn_origin %>/images/fluid-icon.png" title="DevDocs">
-  <link rel="apple-touch-icon" sizes="72x72" href="<%= App.cdn_origin %>/images/apple-icon-72.png">
-  <link rel="apple-touch-icon" sizes="76x76" href="<%= App.cdn_origin %>/images/apple-icon-76.png">
-  <link rel="apple-touch-icon" sizes="114x114" href="<%= App.cdn_origin %>/images/apple-icon-114.png">
-  <link rel="apple-touch-icon" sizes="120x120" href="<%= App.cdn_origin %>/images/apple-icon-120.png">
-  <link rel="apple-touch-icon" sizes="144x144" href="<%= App.cdn_origin %>/images/apple-icon-144.png">
-  <link rel="apple-touch-icon" sizes="152x152" href="<%= App.cdn_origin %>/images/apple-icon-152.png">
-  <link rel="apple-touch-icon" sizes="160x160" href="<%= App.cdn_origin %>/images/apple-icon-160.png">
-  <link rel="mask-icon" href="<%= App.cdn_origin %>/images/webkit-mask-icon.svg" color="#398df0">
+  <link rel="icon" type="image/x-icon" href="/favicon.ico">
+  <link rel="fluid-icon" href="/images/fluid-icon.png" title="DevDocs">
+  <link rel="apple-touch-icon" sizes="72x72" href="/images/apple-icon-72.png">
+  <link rel="apple-touch-icon" sizes="76x76" href="/images/apple-icon-76.png">
+  <link rel="apple-touch-icon" sizes="114x114" href="/images/apple-icon-114.png">
+  <link rel="apple-touch-icon" sizes="120x120" href="/images/apple-icon-120.png">
+  <link rel="apple-touch-icon" sizes="144x144" href="/images/apple-icon-144.png">
+  <link rel="apple-touch-icon" sizes="152x152" href="/images/apple-icon-152.png">
+  <link rel="apple-touch-icon" sizes="160x160" href="/images/apple-icon-160.png">
+  <link rel="mask-icon" href="/images/webkit-mask-icon.svg" color="#398df0">
   <%= stylesheet_tag 'application' %>
 </head>
 <body>
 <noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
 <%= erb :app -%>
-<%= javascript_tag 'application', asset_host: false %>
+<%= javascript_tag 'application' %>
 <%= javascript_tag 'docs' %><% unless App.production? %>
 <%= javascript_tag 'debug' %><% end %>
 </body>
diff --git a/views/other.erb b/views/other.erb
index 45cab943..abd8bc20 100644
--- a/views/other.erb
+++ b/views/other.erb
@@ -6,18 +6,18 @@
   <% 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 %>
   <meta name="format-detection" content="telephone=no">
   <meta name="theme-color" content="#eee">
-  <meta property="og:image" content="<%= App.cdn_origin %>/images/icon-320.png">
+  <meta property="og:image" content="/images/icon-320.png">
   <title>DevDocs<%= " &mdash; #{@doc['full_name']} documentation" if doc_index_page? %></title>
   <link rel="canonical" href="<%= canonical_origin %><%= request.path %>">
   <link rel="manifest" href="/manifest.json">
-  <link rel="icon" type="image/x-icon" href="<%= App.cdn_origin %>/favicon.ico">
+  <link rel="icon" type="image/x-icon" href="/favicon.ico">
   <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="Search 
DevDocs">
   <%= stylesheet_tag 'application' %>
 </head>
 <body data-doc="<%= CGI::escape_html @doc.to_json %>">
 <noscript class="_fail">DevDocs requires JavaScript to run.</noscript>
 <%= erb :app -%>
-<%= javascript_tag 'application', asset_host: false %><% unless App.production? %>
+<%= javascript_tag 'application' %><% unless App.production? %>
 <%= javascript_tag 'debug' %><% end %>
 </body>
 </html>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]