diff --git a/.env.example b/.env.example index c31d0776cd69..21a60e60d1f3 100644 --- a/.env.example +++ b/.env.example @@ -37,12 +37,16 @@ LOCAL_DEV_CHECK=1 # want to develop ckeditor locally. CKEDITOR_BUILD_DIR=./frontend/src/vendor/ckeditor/ -HOST=0.0.0.0 -PORT=4200 +# Local backend development host and port +HOST=localhost +PORT=3000 +# Local frontend development host and port +FE_HOST=localhost +FE_PORT=4200 # Use this variables to configure hostnames for frontend and backend, e.g. to enable HTTPS in docker development setup OPENPROJECT_DEV_HOST=localhost -OPENPROJECT_DEV_URL=http://${OPENPROJECT_DEV_HOST}:${PORT} +OPENPROJECT_DEV_URL=http://${OPENPROJECT_DEV_HOST}:${FE_PORT} # Select edition from: ['standard','bim'] OPENPROJECT_EDITION=standard diff --git a/Procfile.dev b/Procfile.dev index 26ad472210c8..8c11a9c8489b 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,3 +1,3 @@ -web: bundle exec rails server -p 3000 -b ${HOST:="127.0.0.1"} --environment ${RAILS_ENV:="development"} +web: bundle exec rails server angular: npm run serve worker: bundle exec good_job start diff --git a/app/helpers/frontend_asset_helper.rb b/app/helpers/frontend_asset_helper.rb index f016772c4234..38772224edda 100644 --- a/app/helpers/frontend_asset_helper.rb +++ b/app/helpers/frontend_asset_helper.rb @@ -27,14 +27,19 @@ #++ module FrontendAssetHelper - CLI_DEFAULT_PROXY = "http://localhost:4200".freeze + CLI_DEFAULT_PROXY = begin + host = ENV.fetch("FE_HOST", "localhost") + port = ENV.fetch("FE_PORT", 4200) + "http://#{host}:#{port}" + end + 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? end def self.cli_proxy - ENV.fetch("OPENPROJECT_CLI_PROXY", CLI_DEFAULT_PROXY) + CLI_PROXY end ## diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb index e2bf418d9669..715707dd6b73 100644 --- a/config/constants/settings/definition.rb +++ b/config/constants/settings/definition.rb @@ -537,7 +537,7 @@ class Definition }, host_name: { format: :string, - default: "localhost:3000", + default: -> { "#{ENV.fetch('HOST', 'localhost')}:#{ENV.fetch('PORT', 3000)}" }, default_by_env: { # We do not want to set a localhost host name in production production: nil diff --git a/config/puma.rb b/config/puma.rb index 4fe6d97c7c04..8f225b55914b 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -7,12 +7,13 @@ threads_max_count = OpenProject::Configuration.web_max_threads threads threads_min_count, [threads_min_count, threads_max_count].max -# Specifies the `port` that Puma will listen on to receive requests; default is 3000. -# +# Specifies the address on which Puma will listen on to receive requests; default is localhost. +set_default_host ENV.fetch("HOST") { "localhost" } + +# Specifies the port that Puma will listen on to receive requests; default is 3000. port ENV.fetch("PORT") { 3000 }.to_i -# Specifies the `environment` that Puma will run in. -# +# Specifies the environment that Puma will run in. environment ENV.fetch("RAILS_ENV") { "development" } # Specifies the number of `workers` to boot in clustered mode. diff --git a/docker-compose.override.example.yml b/docker-compose.override.example.yml index f1bf691b9fbe..85dc5a5a972b 100644 --- a/docker-compose.override.example.yml +++ b/docker-compose.override.example.yml @@ -3,23 +3,23 @@ services: backend: - environment: - OPENPROJECT_CLI_PROXY: "http://localhost:${PORT}" + # use these ports to be able to access the stack under http://localhost:3000 ports: - - "3000:3000" + - "${PORT:-3000}:3000" frontend: + # use these ports to be able to access the stack under http://localhost:3000 ports: - - "${PORT}:4200" + - "${FE_PORT:-4200}:4200" - db: - ports: - - '5432:5432' + # db: + # ports: + # - '5432:5432' - db-test: - ports: - - '5433:5432' + # db-test: + # ports: + # - '5433:5432' - chrome: - ports: - - '5900:5900' + # chrome: + # ports: + # - '5900:5900' diff --git a/docs/development/development-environment/docker/README.md b/docs/development/development-environment/docker/README.md index a0131770acfc..e9f54ab237dc 100644 --- a/docs/development/development-environment/docker/README.md +++ b/docs/development/development-environment/docker/README.md @@ -106,8 +106,9 @@ directory will not end up with files owned by root. You also will want to create a `docker-compose.override.yml` file, which can contain the port exposure for your containers. Those are excluded from the main compose file `docker-compose.yml` for sanity reasons. If any port is -already in use, `docker compose` won't start and as you cannot disable the exposed port in -the `docker-compose.override.yml` file, you would have to alter the original `docker-compose.yml`. +already in use, `docker compose` won't start and will require explicit override in the `docker-compose.override.yml` +file (see instructions for [!reset](https://docs.docker.com/reference/compose-file/merge/#reset-value) and +[!override](https://docs.docker.com/reference/compose-file/merge/#replace-value)). There is an example you can use out of the box. diff --git a/frontend/cli_to_rails_proxy.js b/frontend/cli_to_rails_proxy.js index 1efa6e90cde0..ca52925bde70 100644 --- a/frontend/cli_to_rails_proxy.js +++ b/frontend/cli_to_rails_proxy.js @@ -1,9 +1,10 @@ -const PROXY_HOSTNAME = process.env.PROXY_HOSTNAME || 'localhost'; +const PROXY_HOSTNAME = process.env.PROXY_HOSTNAME || process.env.HOST || 'localhost'; +const PORT = process.env.PORT || '3000'; const PROXY_CONFIG = [ { "context": ['/**'], - "target": `http://${PROXY_HOSTNAME}:3000`, + "target": `http://${PROXY_HOSTNAME}:${PORT}`, "secure": false, "timeout": 360000, // "bypass": function (req, res, proxyOptions) { diff --git a/frontend/package.json b/frontend/package.json index 6f8167241ae2..6158f66f6b3d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -166,8 +166,8 @@ "build": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --configuration production --named-chunks --source-map", "build:watch": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --watch --named-chunks", "tokens:generate": "theo src/app/spot/styles/tokens/tokens.yml --transform web --format sass,json --dest src/app/spot/styles/tokens/dist", - "serve": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve --host 0.0.0.0 --public-host http://${PROXY_HOSTNAME:-localhost}:4200", - "serve:test": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve --host 0.0.0.0 --disable-host-check --public-host http://frontend-test:4200", + "serve": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve --host ${FE_HOST:-localhost} --port ${FE_PORT:-4200} --public-host http://${PROXY_HOSTNAME:-localhost}:${FE_PORT:-4200}", + "serve:test": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve --host ${FE_HOST:-localhost} --port ${FE_PORT:-4200} --disable-host-check --public-host http://frontend-test:${FE_PORT:-4200}", "test": "ng test --watch=false", "test:watch": "ng test --watch=true", "lint": "esprint check",