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

Limit Webpack dev server allowed CORS origins #11866

Merged
merged 2 commits into from
Feb 11, 2025
Merged
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
CONFIG = config/application.yml
HOST ?= localhost
PORT ?= 3000
ORIGIN_PORT ?= $(PORT)
GZIP_COMMAND ?= gzip
ARTIFACT_DESTINATION_FILE ?= ./tmp/idp.tar.gz

Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
web: WEBPACK_PORT=${WEBPACK_PORT:-3035} bundle exec rackup config.ru --port ${PORT:-3000} --host ${FOREMAN_HOST:-${HOST:-localhost}}
worker: bundle exec good_job start
js: WEBPACK_PORT=${WEBPACK_PORT:-3035} yarn webpack --watch
js: WEBPACK_PORT=${WEBPACK_PORT:-3035} ORIGIN_PORT=${ORIGIN_PORT:-3000} yarn webpack --watch
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for creating a separate environment variable copying PORT is that the behavior of Foreman is to assign a different port value for each process (see ddollar/foreman#110, ddollar/foreman#714). If we just passed PORT, it would actually assign 3200, since this is the third process in the Procfile.

css: yarn build:css --watch
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const isLocalhost = host === 'localhost';
const isProductionEnv = env === 'production';
const mode = isProductionEnv ? 'production' : 'development';
const hashSuffix = isProductionEnv ? '-[chunkhash:8].digested' : '';
const originPort = process.env.ORIGIN_PORT || 3000;
const devServerPort = process.env.WEBPACK_PORT;
const devtool = process.env.WEBPACK_DEVTOOL || (isProductionEnv ? 'source-map' : 'eval-source-map');

Expand Down Expand Up @@ -97,7 +98,7 @@ module.exports = /** @type {import('webpack').Configuration} */ ({
publicPath: './public',
port: Number(devServerPort),
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Origin': `http://${host}:${originPort}`,
'Cache-Control': 'no-store',
Vary: '*',
},
Expand Down