Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting dev asset proxy to false #17035

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/helpers/frontend_asset_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ module FrontendAssetHelper
CLI_PROXY = ENV.fetch("OPENPROJECT_CLI_PROXY", CLI_DEFAULT_PROXY)

def self.assets_proxied?
ENV["OPENPROJECT_DISABLE_DEV_ASSET_PROXY"].blank? && !Rails.env.production? && cli_proxy.present?
override = ActiveModel::Type::Boolean.new.cast ENV.fetch("OPENPROJECT_DISABLE_DEV_ASSET_PROXY", nil)
return override unless override.nil?

!Rails.env.production? && cli_proxy.present?
end

def self.cli_proxy
Expand Down
9 changes: 8 additions & 1 deletion bin/setup_dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
# Deletes bundled javascript assets and rebuilds them.
# Useful for when your frontend doesn't work (jQuery not defined etc.) for seemingly no reason at all.

NPM_COMMAND="ci"

# allow to speed-up boot by using npm install instead of npm ci
if [ "$1" = "fast" ]; then
NPM_COMMAND="install"
fi

yell() { echo -e "$0: $*" >&2; }
die() { yell "$*"; exit 1; }
try() { eval "$@" || die "\n\nFailed to run '$*', check log/setup_dev.log for more information."; }
Expand All @@ -18,7 +25,7 @@ echo "Removing public assets"
try 'rm -rf public/assets >> log/setup_dev.log'

echo "Installing node_modules ... "
try '(cd frontend && npm ci) >> log/setup_dev.log'
try "(cd frontend && npm $NPM_COMMAND) >> log/setup_dev.log"

echo "Linking plugin modules"
try 'bundle exec rake openproject:plugins:register_frontend >> log/setup_dev.log'
Expand Down
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
if ENV["OPENPROJECT_DEV_EXTRA_HOSTS"].present?
config.hosts.push(*ENV["OPENPROJECT_DEV_EXTRA_HOSTS"].split(","))
end

config.hosts.push /\A\w+\.openproject-dev\.com\z/
end

ActiveRecord::Base.logger = ActiveSupport::Logger.new($stdout) unless String(ENV.fetch("SILENCE_SQL_LOGS", nil)).to_bool
2 changes: 1 addition & 1 deletion config/initializers/secure_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
end

# Add proxy configuration for Angular CLI to csp
if FrontendAssetHelper.assets_proxied?
if FrontendAssetHelper.assets_proxied? && FrontendAssetHelper.cli_proxy.present?
proxied = ["ws://#{Setting.host_name}", "http://#{Setting.host_name}",
FrontendAssetHelper.cli_proxy.sub("http", "ws"), FrontendAssetHelper.cli_proxy]
connect_src += proxied
Expand Down
17 changes: 8 additions & 9 deletions spec/helpers/frontend_asset_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@

RSpec.describe FrontendAssetHelper do
describe "#include_frontend_assets" do
context "when in development or test",
with_env: { "OPENPROJECT_DISABLE_DEV_ASSET_PROXY" => "" } do
before do
allow(Rails.env).to receive(:production?).and_return(false)
end
before do
allow(described_class).to receive(:assets_proxied?).and_return(proxied)
end

context "when proxied" do
let(:proxied) { true }

it "returns the proxied frontend server" do
expect(helper.include_frontend_assets).to match(%r{script src="http://(frontend-test|localhost):4200/assets/frontend/main(.*).js"})
Expand All @@ -51,10 +52,8 @@
end
end

context "when in production" do
before do
allow(Rails.env).to receive(:production?).and_return(true)
end
context "when not proxied" do
let(:proxied) { false }

it "returns the path to the asset" do
expect(helper.include_frontend_assets).to match(%r{script src="/assets/frontend/main(.*).js"})
Expand Down
Loading