diff options
author | Mike Greiling <mike@pixelcog.com> | 2017-06-28 21:57:35 -0500 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2017-06-28 22:26:16 -0500 |
commit | 3137b886b84e2c3670b305a8194a3532afe541be (patch) | |
tree | 60a567b30ca001e9658076d534c90dfc4f17f9c3 /app/helpers | |
parent | 5b43aa955737f002be3d197c9f7b4d3374d0ad69 (diff) | |
download | gitlab-ce-3137b886b84e2c3670b305a8194a3532afe541be.tar.gz |
configure webpack publicPath dynamically to account for CDN or relative path settings
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/webpack_helper.rb | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/app/helpers/webpack_helper.rb b/app/helpers/webpack_helper.rb index 6bacda9fe75..0386df22374 100644 --- a/app/helpers/webpack_helper.rb +++ b/app/helpers/webpack_helper.rb @@ -11,20 +11,29 @@ module WebpackHelper paths = Webpack::Rails::Manifest.asset_paths(source) if extension - paths = paths.select { |p| p.ends_with? ".#{extension}" } + paths.select! { |p| p.ends_with? ".#{extension}" } end - # include full webpack-dev-server url for rspec tests running locally + force_host = webpack_public_host + if force_host + paths.map! { |p| "#{force_host}#{p}" } + end + + paths + end + + def webpack_public_host if Rails.env.test? && Rails.configuration.webpack.dev_server.enabled host = Rails.configuration.webpack.dev_server.host port = Rails.configuration.webpack.dev_server.port protocol = Rails.configuration.webpack.dev_server.https ? 'https' : 'http' - - paths.map! do |p| - "#{protocol}://#{host}:#{port}#{p}" - end + "#{protocol}://#{host}:#{port}" + else + ActionController::Base.asset_host.try(:chomp, '/') end + end - paths + def webpack_public_path + "#{webpack_public_host}/#{Rails.application.config.webpack.public_path}/" end end |