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

RFC: Exporting start script to facilitate custom start scripts in a CRA app without ejecting #3926

Closed

Conversation

benglass
Copy link

The use-case we had in mind was customizing the start script without ejecting (for example to add a listener for API calls to proxy them to a separate API server so the web app can talk to it without needing to use CORS). The thought was that if react-scripts start script exported a function to create the dev server then our code could simply require the start script and then add our own custom logic.

The code in this PR is for illustration/discussion purposes only, I havent run it. I wanted to see what your thoughts on this approach were or if there is another way to achieve our use case.

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

start()
.then(
({ devServer, host, port, launchBrowser }) => {
// Launch WebpackDevServer.
Copy link
Author

Choose a reason for hiding this comment

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

If you require'd this module, you could call start() yourself and then off it to get the devServer/host/port/launchBrowser methods and launch the server yourself.

// my-code/scripts/start.js
const start = require('react-scripts/start');
start
  .then(
    ({ devServer, host, post, openBrowser }) => {
      // boot devServer however you want, maybe as middleware on express server?
   }

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@gaearon
Copy link
Contributor

gaearon commented Feb 3, 2018

Why not just modify start script to do two different things?
Something like

    "start": "concurrently \"npm run start:proxy\" \"npm run start:client\"",
    "start:client": "react-scripts start",
    "start:proxy: "..."

@benglass
Copy link
Author

benglass commented Feb 3, 2018

Good question, primary reason being I was hoping to run the proxy on the same port to avoid the need for CORS which I think would require we have a single server.

@gaearon
Copy link
Contributor

gaearon commented Feb 3, 2018

Please describe your use case in #3366 and we can address it as a part of fixing that issue. Thanks!

@gaearon gaearon closed this Feb 3, 2018
@benglass
Copy link
Author

benglass commented Feb 3, 2018

Thanks for pointing me in the direction of the proxy feature, I'll post in #3366 if I find I can't use that feature for my use case.

@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants