mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-23 05:03:04 +08:00
This applies the following when `SiteSetting.content_localization_enabled && SiteSetting.content_localization_crawler_param` and in crawler view. - note: `content_localization_crawler_param` is an experimental site setting - attaches the following in crawler view, depending on the values in `SiteSetting.content_localization_supported_locales`, assuming en, ja, ko. ([old](https://developers.google.com/search/blog/2013/04/x-default-hreflang-for-international-pages) but likely relevant) ``` <link rel="alternate" href="https://nat-1.demo-by-discourse.com/" hreflang="x-default"> <link rel="alternate" href="https://nat-1.demo-by-discourse.com/?tl=en" hreflang="en"> <link rel="alternate" href="https://nat-1.demo-by-discourse.com/?tl=ja" hreflang="ja"> <link rel="alternate" href="https://nat-1.demo-by-discourse.com/?tl=ko" hreflang="ko"> ``` - appends the `tl` param based on the presence of it in the incoming request - this method puts every response for crawler requests through Nokogiri parse.. so we'll have to see how this goes in practice ### Video In the following video you can see each page has the code chunk above in `head`, and each navigated page has the appropriate appended URL param. /t/160415
56 lines
1.9 KiB
Ruby
Vendored
56 lines
1.9 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe "Middleware order" do
|
|
let(:expected_middlewares) do
|
|
[
|
|
BlockRequestsMiddleware,
|
|
TestMultisiteMiddleware,
|
|
ActionDispatch::RemoteIp,
|
|
Middleware::RequestTracker,
|
|
MessageBus::Rack::Middleware,
|
|
Middleware::ProcessingRequest,
|
|
Rack::Sendfile,
|
|
ActionDispatch::Static,
|
|
ActionDispatch::Executor,
|
|
Rack::MethodOverride,
|
|
Middleware::EnforceHostname,
|
|
ActionDispatch::RequestId,
|
|
SilenceLogger,
|
|
Middleware::DefaultHeaders,
|
|
ActionDispatch::ShowExceptions,
|
|
ActionDispatch::DebugExceptions,
|
|
ActionDispatch::Callbacks,
|
|
ActionDispatch::Cookies,
|
|
ActionDispatch::Session::DiscourseCookieStore,
|
|
Discourse::Cors,
|
|
ActionDispatch::Flash,
|
|
RspecErrorTracker,
|
|
Middleware::CspScriptNonceInjector,
|
|
Middleware::AnonymousCache,
|
|
ContentSecurityPolicy::Middleware,
|
|
ActionDispatch::PermissionsPolicy::Middleware,
|
|
Rack::Head,
|
|
Rack::ConditionalGet,
|
|
Rack::TempfileReaper,
|
|
Middleware::CrawlerHooks,
|
|
Middleware::OmniauthBypassMiddleware,
|
|
]
|
|
end
|
|
let(:actual_middlewares) { Rails.configuration.middleware.middlewares }
|
|
let(:remote_ip_index) { actual_middlewares.index(ActionDispatch::RemoteIp) }
|
|
let(:request_tracker_index) { actual_middlewares.index(Middleware::RequestTracker) }
|
|
|
|
it "has the correct order of middlewares" do
|
|
expect(actual_middlewares).to eq(expected_middlewares)
|
|
end
|
|
|
|
it "ensures that ActionDispatch::RemoteIp comes before Middleware::RequestTracker" do
|
|
expect(remote_ip_index).to be < request_tracker_index
|
|
end
|
|
|
|
it "ensures that Middleware::DefaultHeaders comes before ActionDispatch::ShowExceptions" do
|
|
default_headers_index = actual_middlewares.index(Middleware::DefaultHeaders)
|
|
show_exceptions_index = actual_middlewares.index(ActionDispatch::ShowExceptions)
|
|
expect(default_headers_index).to be < show_exceptions_index
|
|
end
|
|
end
|