Server rendering with Curi is pretty similar to client side rendering. The server should have a catch all route handler that will respond to all (non-static file) requests.
The above example is very basic. Some other things that you might need to consider are:
- Data loading — You would need to maintain two copies of your routes if you want to handle data fetching on the server differently than it works on the client side. This is not something that I have explored very closely yet, so I don't have any recommendations on exactly how to approach this.
- Code splitting — In order to use dynamic imports on the server, you will probably need to use a Babel plugin like
dynamic-import-nodebreaks Webpack's code splitting. In order for your code to be split into multiple bundles, you should ensure that
dynamic-import-nodeisn't being run when building your client side bundle. The solution used in this experiment is to use the
Then, when starting the server, make sure that BABEL_ENV=server.
If you want to run this code locally, the source code is available on GitHub.