September 2018
Beginner
156 pages
3h 28m
English
As mentioned in the webpack configuration, the entry point to the application is at /src/server/index.js. Let's create the index.js file at this path, and include the following code, which starts the server application at a given port:
import express from 'express';const PORT = process.env.PORT || 3001;const app = express();app.get('*', (req, res) => { res.send(` <!DOCTYPE HTML> <html> <head> <title>React SSR example</title> </head> <body> <main id='app'>Rendered on the server side</main> </body> </html> `);});app.listen(PORT, () => { console.log(`SSR React Router app running at ${PORT}`);});
When you run the npm start command and access the application at the URL http://localhost:3001, the preceding HTML content ...
Read now
Unlock full access