Skip to content
This repository has been archived by the owner on Sep 11, 2018. It is now read-only.

Koa server #25

Closed
lifehackett opened this issue Aug 17, 2015 · 4 comments
Closed

Koa server #25

lifehackett opened this issue Aug 17, 2015 · 4 comments

Comments

@lifehackett
Copy link

I'm fairly new to webpack, but my understanding is you want it to serves up static assets and you would want a second server to handle other types of requests. For example if I want to fetch some data http:localhost:4000/users/1

When you run npm run dev it doesn't appear that a second server is being spun up to handle these requests. How would you recommend setting this up in the starter kit ecosystem?

Thanks!

@dvdzkwsk
Copy link
Owner

Yeah you're definitely right about that. I've yet to do it successfully so am still searching for the correct way. Maybe I'll spend some quality time with it tomorrow to see how this should be handled, as the server portion of the starter kit needs a lot of TLC.

I'll get back to you if I figure anything out.

@lifehackett
Copy link
Author

So I decided to sort of usurp your /server directory for this purpose, which I think is setup for server rendering, but isn't something I am that familiar with nor needed at the moment since its only going to be used locally. I then update the Procfile to spin up my koa server and the webpack dev environment.

When I used webpack for a heavy client and rails for a backend API I used a setup inspired by this example https://github.com/justin808/react-webpack-rails-tutorial

I figured I'd pass the info along in case it helped.

@dvdzkwsk
Copy link
Owner

@lifehackett I've started work on a branch (https://github.com/davezuko/react-redux-starter-kit/tree/feature/development-server) that will increase the cohesion between webpack-dev-server and Koa. It will probably still be at least a week before I'm able to merge it into master, but here's what's new so far:

  • The npm run dev task will run both servers side-by-side, rather than just webpack-dev-server.
  • Koa server is now pre-processed with babel/register, so it can directly use the React app without having to precompile it. This means it can be smarter about rendering routes and can much more easily inject data into the compiled markup.
  • Implemented nodemon, so if you change anything in server/client the server will reload as well. Most universal examples I've seen don't do this, which means the server rendering quickly gets out of date.

The biggest hurdle I'm facing due to this integration, however, is that there's no easy way to perform non-js imports. Since the application required in the server is not processed with webpack, you lose out not only on those imports but also on things like path aliases. It's really nice having a more convenient development mode, but I'm not sure if the tradeoffs are worth it.

@dvdzkwsk
Copy link
Owner

Closing this since the server is no more.

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

No branches or pull requests

2 participants