-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
fix: enable serving in separate process from the build #332
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,9 @@ module.exports = { | |
// FastBoot. This one is returned here as default configuration in order to make it | ||
// available at run time. | ||
config: function (environment, runConfig) { | ||
if (process.env.DISABLE_CSP) { | ||
return {}; | ||
} | ||
debug('### Cache run-time config locally in config hook'); | ||
|
||
// store run config to be available later | ||
|
@@ -101,6 +104,9 @@ module.exports = { | |
}, | ||
|
||
serverMiddleware: function ({ app: expressApp, options }) { | ||
if (process.env.DISABLE_CSP) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to have an environment variable to disable CSP in addon hard-coded? Having it in userland configuration would reduce complexity. A consumer would not need to look into addons documentation but only in project's CSP configuration to discover and understand the environment variable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this allows libraries to easily turn it off via config when running the command vs needing to learn about and change config files |
||
return; | ||
} | ||
debug('### Register middleware to set CSP headers in development server'); | ||
|
||
const requiresLiveReload = options.liveReload; | ||
|
@@ -124,10 +130,13 @@ module.exports = { | |
// Use policy for test environment if both of these conditions are met: | ||
// 1. the request is for tests and | ||
// 2. the build include tests | ||
let buildIncludeTests = this.app.tests; | ||
const env = process.env.EMBER_ENV; | ||
let buildIncludeTests = this.app | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we actually need to determine if build includes tests. Maybe it's enough to analyze if the request is for tests? Is there a case of legitim requests for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
? this.app.tests | ||
: process.env.USE_TESTS_CSP || false; | ||
let isRequestForTests = | ||
req.originalUrl.startsWith('/tests') && buildIncludeTests; | ||
let environment = isRequestForTests ? 'test' : this.app.env; | ||
let environment = isRequestForTests ? 'test' : env; | ||
|
||
debug( | ||
buildIncludeTests | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to return after setting
_runConfig
, because https://github.com/rwjblue/ember-cli-content-security-policy/blob/master/lib/utils.js#L96 was null (Cannot read properties of null (reading 'contentSecurityPolicy')
)