- The browser makes a request to get index.html from the server.
- Express sends index.html to the browser.
- The browser executes the bundle referred to in a script tag with a defer attribute.
- React components are mounted for the first time.
- A route returns a list of albums.
unicodesnowman.pngπpublicclass SingleSong extends React.Componentπclientimport app from './app'πclientrequire('./app')πserverArtist.findAll()πserver<script defer src="/bundle.js"></script>πpublic/client- Personally, I prefer to have the
index.htmlfile inside of thepublicdirectory and serve it from from/server/index.jsusing:// Static file-serving middleware app.use(express.static(path.join(__dirname, '..', 'public')))
- Nonetheless, it boils down to preference. Juke has the
index.htmlfile in theclientdirectory and serves it up from/server/index.jsusing:// Sends our index.html (the "single page" of our SPA) app.get('/', (req, res, next) => { res.sendFile(path.join(__dirname, '..', 'client', 'index.html')) })
- Personally, I prefer to have the
- Question: When do you need to pass
propsinto a react componentsconstructor/superfunctions? Sometimes the solution code has it, sometimes it doesn't.- Answer: Please refer to "Why Do We Write super(props)?".