For this recipe, we are going to implement a basic todo list pulled from an API to show how to connect Redux to our application using SSR:
- The first thing we need to do is to add a simple API to display a to-do list:
import express from 'express'; const router = express.Router(); // Mock data, this should come from a database.... const todo = [ { id: 1, title: 'Go to the Gym' }, { id: 2, title: 'Dentist Appointment' }, { id: 3, title: 'Finish homework' } ]; router.get('/todo/list', (req, res, next) => { res.json({ response: todo }); }); export default router;
- The second step is to import this API controller into our src/server/index.js file and add it as middleware on the /api route: ...