Setting up SSR in Express.js to render React on the server
In this example, the first step is to implement basic SSR on the backend. We are going to extend this functionality later to validate the authentication of the user. An authenticated user allows us to execute Apollo or GraphQL requests rather than only render the pure React markup. First, we need some new packages. Because we are going to use universally rendered React code, we require an advanced webpack configuration. Therefore, we will install the following packages:
npm install --save-dev webpack-dev-middleware webpack-hot-middleware @babel/cli
Let's quickly go through the packages that we are installing. We only need these packages for development:
- The first webpack module, called
webpack-dev-middleware
, allows the backend to serve bundles that are generated by webpack, but from memory and without creating files. This is convenient for cases in which we need to run JavaScript directly and do not want...