rename route `/javascripts` to `/theme-javascripts` (#6495)
This commit is contained in:
parent
c104256991
commit
99d1ded3b3
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
class JavascriptsController < ApplicationController
|
||||
class ThemeJavascriptsController < ApplicationController
|
||||
DISK_CACHE_PATH = "#{Rails.root}/tmp/javascript-cache"
|
||||
|
||||
skip_before_action(
|
|
@ -7,7 +7,7 @@ class JavascriptCache < ActiveRecord::Base
|
|||
before_save :update_digest
|
||||
|
||||
def url
|
||||
"#{GlobalSetting.cdn_url}#{GlobalSetting.relative_url_root}/javascripts/#{digest}.js"
|
||||
"#{GlobalSetting.cdn_url}#{GlobalSetting.relative_url_root}/theme-javascripts/#{digest}.js"
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -191,7 +191,7 @@ server {
|
|||
# This big block is needed so we can selectively enable
|
||||
# acceleration for backups and avatars
|
||||
# see note about repetition above
|
||||
location ~ ^/(letter_avatar/|user_avatar|highlight-js|stylesheets|favicon/proxied|service-worker) {
|
||||
location ~ ^/(letter_avatar/|user_avatar|highlight-js|stylesheets|theme-javascripts|favicon/proxied|service-worker) {
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Request-Start "t=${msec}";
|
||||
|
|
|
@ -450,7 +450,7 @@ Discourse::Application.routes.draw do
|
|||
|
||||
get "stylesheets/:name.css.map" => "stylesheets#show_source_map", constraints: { name: /[-a-z0-9_]+/ }
|
||||
get "stylesheets/:name.css" => "stylesheets#show", constraints: { name: /[-a-z0-9_]+/ }
|
||||
get "javascripts/:digest.js" => "javascripts#show", constraints: { digest: /\h{40}/ }
|
||||
get "theme-javascripts/:digest.js" => "theme_javascripts#show", constraints: { digest: /\h{40}/ }
|
||||
|
||||
post "uploads" => "uploads#create"
|
||||
post "uploads/lookup-urls" => "uploads#lookup_urls"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
require 'rails_helper'
|
||||
|
||||
describe JavascriptsController do
|
||||
describe ThemeJavascriptsController do
|
||||
let(:theme) { Fabricate(:theme) }
|
||||
let(:theme_field) { ThemeField.create!(theme: theme, target_id: 0, name: "header", value: "<a>html</a>") }
|
||||
let(:javascript_cache) { JavascriptCache.create!(content: 'console.log("hello");', theme_field: theme_field) }
|
||||
|
@ -11,7 +11,7 @@ describe JavascriptsController do
|
|||
# actually set digest to make sure 404 is raised by router
|
||||
javascript_cache.update_attributes(digest: digest)
|
||||
|
||||
get "/javascripts/#{digest}.js"
|
||||
get "/theme-javascripts/#{digest}.js"
|
||||
end
|
||||
|
||||
it 'only accepts 40-char hexdecimal digest name' do
|
||||
|
@ -37,18 +37,18 @@ describe JavascriptsController do
|
|||
it 'considers the database record as the source of truth' do
|
||||
clear_disk_cache
|
||||
|
||||
get "/javascripts/#{javascript_cache.digest}.js"
|
||||
get "/theme-javascripts/#{javascript_cache.digest}.js"
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.body).to eq(javascript_cache.content)
|
||||
|
||||
javascript_cache.destroy!
|
||||
|
||||
get "/javascripts/#{javascript_cache.digest}.js"
|
||||
get "/theme-javascripts/#{javascript_cache.digest}.js"
|
||||
expect(response.status).to eq(404)
|
||||
end
|
||||
|
||||
def clear_disk_cache
|
||||
`rm #{JavascriptsController::DISK_CACHE_PATH}/*`
|
||||
`rm #{ThemeJavascriptsController::DISK_CACHE_PATH}/*`
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue