JasonBoy / koa-web-kit

🚀A Modern, Production-Ready, and Full-Stack Node Web Framework with React
MIT License
214 stars 41 forks source link

Add React SSR support #9

Closed JasonBoy closed 6 years ago

JasonBoy commented 6 years ago

🎉 Add simple React SSR(Server Side Rendering) support for your SPA app

also including the following changes:

How to enable:

  1. First enable ENABLE_SSR: true in your app-config.js or env, also HMR should be disabled(maybe can use them together in the future) since we are using our own server logic to do SSR, also set STATIC_PREFIX to some not empty value, e.g /static, to prevent html error when access '/' home page, which is handle directly by static middleware without rendering by nunjucks.
  2. You will need to use npm run watch(your client react app)
  3. Use npm run ssr -- --watch to transpile the SSR related source code to be required in your node.js code, see routes/index.js
  4. Use npm start(your koa server) to let the koa server do SSR stuff
  5. Go to the browser to see the responsed html doc

TODOs