FEATURE: allow plugins to easily detect if running in Rack

Usage: Discourse.running_in_rack? to tell if rack was booted
This commit is contained in:
Sam 2017-11-16 08:39:11 +11:00
parent 20fbf81505
commit f52111f787
3 changed files with 19 additions and 0 deletions

View File

@ -1,5 +1,8 @@
# This file is used by Rack-based servers to start the application. # 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__) require ::File.expand_path('../config/environment', __FILE__)
map ActionController::Base.config.try(:relative_url_root) || "/" do map ActionController::Base.config.try(:relative_url_root) || "/" do
run Discourse::Application run Discourse::Application
end end

View File

@ -499,4 +499,8 @@ module Discourse
nil nil
end end
def self.running_in_rack?
ENV["DISCOURSE_RUNNING_IN_RACK"] == "1"
end
end end

View File

@ -15,6 +15,18 @@ describe Discourse do
end 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 'base_url' do
context 'when https is off' do context 'when https is off' do
before do before do