FEATURE: add clean support for running Discourse in a subfolder

To setup set DISCOURSE_RELATIVE_URL_ROOT to the folder you wish
This commit is contained in:
Sam
2015-03-09 11:45:36 +11:00
parent 4c4183228f
commit f5af4768eb
27 changed files with 81 additions and 34 deletions

View File

@ -17,11 +17,12 @@ module Middleware
end
def call(env)
is_asset = (env['REQUEST_PATH'] =~ /^\/assets\//)
root = "#{GlobalSetting.relative_url_root}/assets/"
is_asset = env['REQUEST_PATH'] && env['REQUEST_PATH'].starts_with?(root)
# hack to bypass all middleware if serving assets, a lot faster 4.5 seconds -> 1.5 seconds
if (etag = env['HTTP_IF_NONE_MATCH']) && is_asset
name = $'
name = env['REQUEST_PATH'][(root.length)..-1]
etag = etag.gsub "\"", ""
asset = Rails.application.assets.find_asset(name)
if asset && asset.digest == etag