From 2c8e3fbbfbe26fb78418324ef14caf13ab207623 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 25 Sep 2017 04:04:04 +0200 Subject: Generate 500.html with assets:precompile, remove loading from Google Fonts (#5067) --- lib/tasks/assets.rake | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 lib/tasks/assets.rake (limited to 'lib/tasks/assets.rake') diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake new file mode 100644 index 000000000..cd0a3bd2b --- /dev/null +++ b/lib/tasks/assets.rake @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +if Rake::Task.task_defined?('assets:precompile') + Rake::Task['assets:precompile'].enhance do + html = ApplicationController.render('errors/500', layout: 'error') + File.write(Rails.root.join('public', '500.html'), html) + end +end -- cgit From 0fea700c7be051ace98c2b3426531862c73565bb Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Mon, 25 Sep 2017 23:58:12 +0900 Subject: Refresh manifest before generate 500.html (#5090) --- lib/tasks/assets.rake | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/tasks/assets.rake') diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index cd0a3bd2b..ad7c6ba90 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -1,8 +1,17 @@ # frozen_string_literal: true -if Rake::Task.task_defined?('assets:precompile') - Rake::Task['assets:precompile'].enhance do +namespace :assets do + desc 'Generate 500.html' + task :generate_500 do html = ApplicationController.render('errors/500', layout: 'error') File.write(Rails.root.join('public', '500.html'), html) end end + +if Rake::Task.task_defined?('assets:precompile') + Rake::Task['assets:precompile'].enhance do + Webpacker::Manifest.load + + Rake::Task['assets:generate_500'].invoke + end +end -- cgit From 3b60832214fdd9d8b5fd01e9a177a6dde5259907 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 25 Sep 2017 23:05:54 +0200 Subject: New error page graphic. Other error page improvements (#5099) - 500.html generated with admin-set default locale if set - Error page `` includes Mastodon site title - 500 title changed to "This page is not correct" (ref: <https://www.youtube.com/watch?v=2VCAP_seh1A>) - 500 content appended with "on our end" to make clear it's not user's fault --- app/javascript/styles/basics.scss | 5 ++--- app/views/errors/500.html.haml | 4 ++-- app/views/layouts/error.html.haml | 4 ++-- config/locales/en.yml | 4 +++- lib/tasks/assets.rake | 7 ++++--- public/oops.gif | Bin 0 -> 95633 bytes public/oops.png | Bin 120305 -> 0 bytes 7 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 public/oops.gif delete mode 100644 public/oops.png (limited to 'lib/tasks/assets.rake') diff --git a/app/javascript/styles/basics.scss b/app/javascript/styles/basics.scss index 48652a035..96f0023c3 100644 --- a/app/javascript/styles/basics.scss +++ b/app/javascript/styles/basics.scss @@ -70,9 +70,8 @@ body { .dialog img { display: block; - margin: 20px auto; - margin-top: 50px; - max-width: 600px; + margin: 0 auto; + max-width: 470px; width: 100%; height: auto; } diff --git a/app/views/errors/500.html.haml b/app/views/errors/500.html.haml index e124be551..6244ff209 100644 --- a/app/views/errors/500.html.haml +++ b/app/views/errors/500.html.haml @@ -1,5 +1,5 @@ - content_for :page_title do - = t('errors.500') + = t('errors.500.title') - content_for :content do - = t('errors.500') + = t('errors.500.content') diff --git a/app/views/layouts/error.html.haml b/app/views/layouts/error.html.haml index 0b5f908ae..31f322096 100644 --- a/app/views/layouts/error.html.haml +++ b/app/views/layouts/error.html.haml @@ -3,12 +3,12 @@ %head %meta{ content: 'text/html; charset=UTF-8', 'http-equiv' => 'Content-Type' }/ %meta{ charset: 'utf-8' }/ - %title= yield :page_title + %title= safe_join([yield(:page_title), title], ' - ') %meta{ content: 'width=device-width,initial-scale=1', name: 'viewport' }/ = stylesheet_pack_tag 'common', media: 'all' = stylesheet_pack_tag Setting.default_settings['theme'], media: 'all' %body.error .dialog - %img{ alt: 'Mastodon', src: '/oops.png' }/ + %img{ alt: title, src: '/oops.gif' }/ %div %h1= yield :content diff --git a/config/locales/en.yml b/config/locales/en.yml index cc440e1b0..f87d8532c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -310,7 +310,9 @@ en: content: Security verification failed. Are you blocking cookies? title: Security verification failed '429': Throttled - '500': We're sorry, but something went wrong. + '500': + content: We're sorry, but something went wrong on our end. + title: This page is not correct noscript_html: To use the Mastodon web application, please enable JavaScript. Alternatively, try one of the <a href="https://github.com/tootsuite/documentation/blob/master/Using-Mastodon/Apps.md">native apps</a> for Mastodon for your platform. exports: blocks: You block diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index ad7c6ba90..2ef72fdef 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -3,15 +3,16 @@ namespace :assets do desc 'Generate 500.html' task :generate_500 do - html = ApplicationController.render('errors/500', layout: 'error') - File.write(Rails.root.join('public', '500.html'), html) + I18n.with_locale(ENV['DEFAULT_LOCALE'] || I18n.default_locale) do + html = ApplicationController.render('errors/500', layout: 'error') + File.write(Rails.root.join('public', '500.html'), html) + end end end if Rake::Task.task_defined?('assets:precompile') Rake::Task['assets:precompile'].enhance do Webpacker::Manifest.load - Rake::Task['assets:generate_500'].invoke end end diff --git a/public/oops.gif b/public/oops.gif new file mode 100644 index 000000000..ad19c4e10 Binary files /dev/null and b/public/oops.gif differ diff --git a/public/oops.png b/public/oops.png deleted file mode 100644 index 0abddad3e..000000000 Binary files a/public/oops.png and /dev/null differ -- cgit From b32a1d575469aeb3d74da93d861b77df55715e1b Mon Sep 17 00:00:00 2001 From: nullkal <nullkal@nil.nu> Date: Tue, 26 Sep 2017 18:55:33 +0900 Subject: Refactor 500 file generation for future extension (#5105) --- lib/tasks/assets.rake | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'lib/tasks/assets.rake') diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index 2ef72fdef..92d5aea80 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -1,18 +1,22 @@ # frozen_string_literal: true +def render_static_page(action, dest:, **opts) + I18n.with_locale(ENV['DEFAULT_LOCALE'] || I18n.default_locale) do + html = ApplicationController.render(action, opts) + File.write(dest, html) + end +end + namespace :assets do - desc 'Generate 500.html' - task :generate_500 do - I18n.with_locale(ENV['DEFAULT_LOCALE'] || I18n.default_locale) do - html = ApplicationController.render('errors/500', layout: 'error') - File.write(Rails.root.join('public', '500.html'), html) - end + desc 'Generate static pages' + task :generate_static_pages do + render_static_page 'errors/500', layout: 'error', dest: Rails.root.join('public', '500.html') end end if Rake::Task.task_defined?('assets:precompile') Rake::Task['assets:precompile'].enhance do Webpacker::Manifest.load - Rake::Task['assets:generate_500'].invoke + Rake::Task['assets:generate_static_pages'].invoke end end -- cgit From 901fc48aaec8c6c5f1ae3c210c701abce3c03c7c Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi <ykzts@desire.sh> Date: Wed, 27 Sep 2017 21:41:54 +0900 Subject: Upgrade Webpacker to version 3.0.1 (#5122) --- Gemfile | 2 +- Gemfile.lock | 8 +++++--- Procfile.dev | 2 +- bin/webpack | 7 +++---- bin/webpack-dev-server | 47 ++++++++++++++++++++++++++++++++++++----------- config/webpacker.yml | 22 ++++++++++++++++++++-- lib/tasks/assets.rake | 2 +- 7 files changed, 67 insertions(+), 23 deletions(-) (limited to 'lib/tasks/assets.rake') diff --git a/Gemfile b/Gemfile index 248171680..09b3b8eff 100644 --- a/Gemfile +++ b/Gemfile @@ -67,7 +67,7 @@ gem 'sprockets-rails', '~> 3.2', require: 'sprockets/railtie' gem 'statsd-instrument', '~> 2.1' gem 'twitter-text', '~> 1.14' gem 'tzinfo-data', '~> 1.2017' -gem 'webpacker', '~> 2.0' +gem 'webpacker', '~> 3.0' gem 'webpush' gem 'json-ld-preloaded', '~> 2.2.1' diff --git a/Gemfile.lock b/Gemfile.lock index 89ee34cb6..73419fd28 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -335,6 +335,8 @@ GEM rack-cors (0.4.1) rack-protection (2.0.0) rack + rack-proxy (0.6.2) + rack rack-test (0.7.0) rack (>= 1.0, < 3) rack-timeout (0.4.2) @@ -510,9 +512,9 @@ GEM addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff - webpacker (2.0) + webpacker (3.0.1) activesupport (>= 4.2) - multi_json (~> 1.2) + rack-proxy (>= 0.6.1) railties (>= 4.2) webpush (0.3.2) hkdf (~> 0.2) @@ -621,7 +623,7 @@ DEPENDENCIES tzinfo-data (~> 1.2017) uglifier (~> 3.2) webmock (~> 3.0) - webpacker (~> 2.0) + webpacker (~> 3.0) webpush RUBY VERSION diff --git a/Procfile.dev b/Procfile.dev index 9084b4263..e75a491c7 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,4 +1,4 @@ web: PORT=3000 bundle exec puma -C config/puma.rb sidekiq: PORT=3000 bundle exec sidekiq stream: PORT=4000 yarn run start -webpack: ./bin/webpack-dev-server --host 0.0.0.0 +webpack: ./bin/webpack-dev-server --listen-host 0.0.0.0 diff --git a/bin/webpack b/bin/webpack index 867550eb8..528233a78 100755 --- a/bin/webpack +++ b/bin/webpack @@ -2,7 +2,6 @@ $stdout.sync = true require "shellwords" -require "yaml" ENV["RAILS_ENV"] ||= "development" RAILS_ENV = ENV["RAILS_ENV"] @@ -20,9 +19,9 @@ unless File.exist?(WEBPACK_CONFIG) exit! end -newenv = { "NODE_PATH" => NODE_MODULES_PATH.shellescape } -cmdline = ["yarn", "run", "webpack", "--", "--config", WEBPACK_CONFIG] + ARGV +env = { "NODE_PATH" => NODE_MODULES_PATH.shellescape } +cmd = [ "#{NODE_MODULES_PATH}/.bin/webpack", "--config", WEBPACK_CONFIG ] + ARGV Dir.chdir(APP_PATH) do - exec newenv, *cmdline + exec env, *cmd end diff --git a/bin/webpack-dev-server b/bin/webpack-dev-server index 0beec3175..c9672f663 100755 --- a/bin/webpack-dev-server +++ b/bin/webpack-dev-server @@ -3,6 +3,7 @@ $stdout.sync = true require "shellwords" require "yaml" +require "socket" ENV["RAILS_ENV"] ||= "development" RAILS_ENV = ENV["RAILS_ENV"] @@ -13,7 +14,9 @@ NODE_ENV = ENV["NODE_ENV"] APP_PATH = File.expand_path("../", __dir__) CONFIG_FILE = File.join(APP_PATH, "config/webpacker.yml") NODE_MODULES_PATH = File.join(APP_PATH, "node_modules") -WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/development.js") +WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js") + +DEFAULT_LISTEN_HOST_ADDR = NODE_ENV == 'development' ? 'localhost' : '0.0.0.0' def args(key) index = ARGV.index(key) @@ -21,23 +24,45 @@ def args(key) end begin - dev_server = YAML.load_file(CONFIG_FILE)["development"]["dev_server"] + dev_server = YAML.load_file(CONFIG_FILE)[RAILS_ENV]["dev_server"] - DEV_SERVER_HOST = "http#{"s" if args('--https') || dev_server["https"]}://#{dev_server["host"]}:#{args('--port') || dev_server["port"]}" + HOSTNAME = args('--host') || dev_server["host"] + PORT = args('--port') || dev_server["port"] + HTTPS = ARGV.include?('--https') || dev_server["https"] + DEV_SERVER_ADDR = "http#{"s" if HTTPS}://#{HOSTNAME}:#{PORT}" + LISTEN_HOST_ADDR = args('--listen-host') || DEFAULT_LISTEN_HOST_ADDR rescue Errno::ENOENT, NoMethodError - puts "Webpack dev_server configuration not found in #{CONFIG_FILE}." - puts "Please run bundle exec rails webpacker:install to install webpacker" + $stdout.puts "Webpack dev_server configuration not found in #{CONFIG_FILE}." + $stdout.puts "Please run bundle exec rails webpacker:install to install webpacker" + exit! +end + +begin + server = TCPServer.new(LISTEN_HOST_ADDR, PORT) + server.close + +rescue Errno::EADDRINUSE + $stdout.puts "Another program is running on port #{PORT}. Set a new port in #{CONFIG_FILE} for dev_server" exit! end -newenv = { - "NODE_PATH" => NODE_MODULES_PATH.shellescape, - "ASSET_HOST" => DEV_SERVER_HOST.shellescape -}.freeze +# Delete supplied host, port and listen-host CLI arguments +["--host", "--port", "--listen-host"].each do |arg| + ARGV.delete(args(arg)) + ARGV.delete(arg) +end + +env = { "NODE_PATH" => NODE_MODULES_PATH.shellescape } -cmdline = ["yarn", "run", "webpack-dev-server", "--", "--progress", "--color", "--config", WEBPACK_CONFIG] + ARGV +cmd = [ + "#{NODE_MODULES_PATH}/.bin/webpack-dev-server", "--progress", "--color", + "--config", WEBPACK_CONFIG, + "--host", LISTEN_HOST_ADDR, + "--public", "#{HOSTNAME}:#{PORT}", + "--port", PORT.to_s +] + ARGV Dir.chdir(APP_PATH) do - exec newenv, *cmdline + exec env, *cmd end diff --git a/config/webpacker.yml b/config/webpacker.yml index aa429a1dd..8d8470651 100644 --- a/config/webpacker.yml +++ b/config/webpacker.yml @@ -4,6 +4,15 @@ default: &default source_path: app/javascript source_entry_path: packs public_output_path: packs + cache_path: tmp/cache/webpacker + + # Additional paths webpack should lookup modules + # ['app/assets', 'engine/foo/app/assets'] + resolved_paths: [] + + # Reload manifest.json on all requests so we reload latest compiled packs + cache_manifest: false + extensions: - .js - .sass @@ -17,16 +26,25 @@ default: &default development: <<: *default + compile: true dev_server: - host: 127.0.0.1 - port: 8080 + host: localhost + port: 3035 + hmr: false https: false test: <<: *default + # Compile test packs to a separate directory public_output_path: packs-test production: <<: *default + + # Production depends on precompilation of packs prior to booting for performance. + compile: false + + # Cache manifest.json for performance + cache_manifest: true diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index 92d5aea80..44896afc7 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -16,7 +16,7 @@ end if Rake::Task.task_defined?('assets:precompile') Rake::Task['assets:precompile'].enhance do - Webpacker::Manifest.load + Webpacker.manifest.refresh Rake::Task['assets:generate_static_pages'].invoke end end -- cgit