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

fix: enable serving in separate process from the build #332

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

runspired
Copy link
Contributor

resolves #331

If serving from a separate command and your build includes tests you will also want to set the env var USE_TESTS_CSP=1.

Optionally if necessary the CSP can be disabled with DISABLE_CSP env var.

@runspired
Copy link
Contributor Author

test failures are unrelated, tests appear to be broken on master

Copy link
Collaborator

@jelhan jelhan left a comment

Choose a reason for hiding this comment

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

Thanks a lot for working on this one. I have a few questions on design.

Didn't had much time to think through it to be honest. Please excuse if the questions sound stupid knowing the details.

@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 /tests if app does not include tests?

Copy link
Contributor Author

@runspired runspired Sep 27, 2022

Choose a reason for hiding this comment

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

  • you can do a build and then serve tests off the build directly.
  • you can name a route tests :(

@@ -101,6 +104,9 @@ module.exports = {
},

serverMiddleware: function ({ app: expressApp, options }) {
if (process.env.DISABLE_CSP) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

@@ -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) {
Copy link

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'))

this._runConfig = runConfig;

if (process.env.DISABLE_CSP) {
  return {};
}

@wozny1989
Copy link

@runspired thanks a lot for this fix!

Any chance of merge it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Breaks if serving separately from build command
4 participants