diff --git a/config.ru b/config.ru index 9a0cd31d678..3c73b82bb19 100644 --- a/config.ru +++ b/config.ru @@ -1,5 +1,8 @@ # This file is used by Rack-based servers to start the application. +ENV["DISCOURSE_RUNNING_IN_RACK"] = "1" + require ::File.expand_path('../config/environment', __FILE__) + map ActionController::Base.config.try(:relative_url_root) || "/" do run Discourse::Application end diff --git a/lib/discourse.rb b/lib/discourse.rb index 24ff23eb05a..73698fe6182 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -499,4 +499,8 @@ module Discourse nil end + def self.running_in_rack? + ENV["DISCOURSE_RUNNING_IN_RACK"] == "1" + end + end diff --git a/spec/components/discourse_spec.rb b/spec/components/discourse_spec.rb index a0047900a86..b9ef0df7d9f 100644 --- a/spec/components/discourse_spec.rb +++ b/spec/components/discourse_spec.rb @@ -15,6 +15,18 @@ describe Discourse do end + context 'running_in_rack' do + after do + ENV.delete("DISCOURSE_RUNNING_IN_RACK") + end + + it 'should not be running in rack' do + expect(Discourse.running_in_rack?).to eq(false) + ENV["DISCOURSE_RUNNING_IN_RACK"] = "1" + expect(Discourse.running_in_rack?).to eq(true) + end + end + context 'base_url' do context 'when https is off' do before do