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

Consolidate HTML + JS Servers #808

Closed
wants to merge 10 commits into from

Conversation

drewpc
Copy link
Collaborator

@drewpc drewpc commented Jan 7, 2017

This PR addresses #807 with the least controversial set of changes. See PR #791 for more discussion on this. Essentially, this PR does the following:

  • Consolidates all Express servers into a single server (removing the requirement for jsPort)
  • If hot === true, webpack-dev-server is used as to create the HTTP/HTTPS server and Express application. react-server piggy backs off of the Express application by injecting itself into the middleware chain after webpack-dev-middleware is injected. No proxying is required.
  • If hot === false, react-server creates the HTTP/HTTPS server and Express application on its own and manually creates and runs a Webpack compiler for the client side code.

In my opinion, this is not the cleanest path for react-server, but it is the least controversial set of changes to the overall infrastructure while still reducing complexity at runtime.

Another method of solving this problem is to stop using webpack-dev-server and attach webpack-dev-middleware to the Express application that react-server creates. This will more easily allow people to use alternatives to Express in the future and keep react-server operating the same in hot/not-hot modes. It does, however, move the client-side HMR mechanism away from something that the Webpack people maintain and over to webpack-hot-middleware. This project supports multiple compilers (which will be useful later), Webpack 2, and seems to be well maintained.

Checkout this patch to see what this code would look like.

As always, feedback is appreciated.

@drewpc drewpc mentioned this pull request Jan 7, 2017
# Conflicts:
#	packages/react-server-cli/package.json
}

let middlewareSetup = (server, rsMiddleware) => {
server.use(compression());
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if that's a problem but it looks like the compression() middleware is used two times in non-hot mode.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks! I fixed that.

# Conflicts:
#	packages/react-server-cli/src/commands/start.js
#	packages/react-server-cli/src/compileClient.js
…moved secondary use of `compression()` in non-hot mode (leftover from when this was used in a secondary Express instance).
# Conflicts:
#	packages/react-server-cli/src/commands/start.js
@drewpc
Copy link
Collaborator Author

drewpc commented Feb 5, 2017

Closing this PR, pending further architecture discussion.

@drewpc drewpc closed this Feb 5, 2017
@drewpc drewpc mentioned this pull request Apr 23, 2019
3 tasks
@drewpc drewpc deleted the patch-consolidate-webservers branch May 10, 2019 20:31
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.

None yet

2 participants