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

Enable enhanced customization of server options #292

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jakedetels
Copy link
Contributor

This pull request aims to enhance the user's ability to customize the options passed to broccoli.server.serve() in a couple different ways.

First, users can customize the http response headers created within lib/middleware.js by including a headers property in the main options object passed in broccoli.server.serve(builder, options). For example, the following options would enable Broccoli to include a CORS header when serving files on http://localhost:4200:

var options = {
  headers: {
    'Access-Control-Allow-Origin': '*'
  }
};

broccoli.server.serve(builder, options);

To allow advanced options like these to be easier configure when using Broccoli CLI, this pull request also expands on lib/cli.js by allowing users to define an optional .broccoli JSON-formatted file within the root directory of their projects. Any configurations defined within that .broccoli file will be pulled whenever calling broccoli serve. For example, the following .broccoli file would cause Broccoli to serve on port 12345 with a CORS header:

//  `.broccoli` file saved in project root
{
  "headers": {
    "Access-Control-Allow-Origin": "*"
  },
  "port": 12345
}

This pull request includes 5 new passing tests in test/options_test.js. To help clean up the console output when running Mocha, there is new option defined called disableLogging which (when set to true) will cause lib/server.js to not call console.log() while the Mocha tests are running.

@jakedetels
Copy link
Contributor Author

@joliss: Any feedback?

@oksuz
Copy link

oksuz commented May 25, 2016

@joliss @jakedetels When do you merge this feature? I need this feature for adding custom headers to server response. Thank you

@stefanpenner
Copy link
Contributor

@jakedetels / @oksuz sorry for the long delay in response. I believe in broad-strokes I agree with this approach.

The code-base has changed some, if you are still using broccoli and would like to rebase and update the code. I would love to revisit this, and help get it in.

@stefanpenner stefanpenner mentioned this pull request Nov 23, 2017
@jakedetels
Copy link
Contributor Author

@stefanpenner: I'll aim to get this PR updated by the end of the month (12/31/2017). If needed sooner, let me know.

@rwjblue
Copy link
Member

rwjblue commented Mar 19, 2018

Friendly ping 🏂

@simonc
Copy link

simonc commented Oct 27, 2019

Faced the issue today, this PR would be very helpful 😊

@lifeart
Copy link
Contributor

lifeart commented Sep 26, 2021

I like idea about additional customization, but I think having multiple ways to do it - not an optimal direction.

We could have .broccoli.js (no need to escape comments, able to have dynamic logic in it for different purposes - serve, build-dev, build-prod) file, with all needed things, including middleware, but it's requires more design work here.

// .broccoli.js

module.exports = async function({env, mode} : { env: 'prod' | 'dev'; mode: 'build' | 'serve' }) {
   return {
      port: 4011,
      host: '192.168.1.1',
      staticHeaders: {
         'Access-Control-Alow-Origin': '*'
      },
      middleware: {
         onError(req, resp, error) {
             //tbd
         },
         onRequest(req, resp, next) {
            //tbd
         },
         postRequest(req, resp) {
             //tbd
          }
      }
   }
}

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

Successfully merging this pull request may close these issues.

6 participants