Skip to content

Instantly share code, notes, and snippets.

@nrl240
Last active July 6, 2020 14:51
Show Gist options
  • Select an option

  • Save nrl240/a7c8464276bf983dfadadc079adfcfa8 to your computer and use it in GitHub Desktop.

Select an option

Save nrl240/a7c8464276bf983dfadadc079adfcfa8 to your computer and use it in GitHub Desktop.
Exit Ticket: Day 13 - Fullstack Data Flow & Juke

Exit Ticket: Day 13 - Fullstack Data Flow & Juke

Pick the correct order for the following flows of data.

  1. The browser makes a request to get index.html from the server.
  2. Express sends index.html to the browser.
  3. The browser executes the bundle referred to in a script tag with a defer attribute.
  4. React components are mounted for the first time.
  5. A route returns a list of albums.

Pick which folder each file or line of code should be under.

  • unicodesnowman.png πŸ‘‰ public
  • class SingleSong extends React.Component πŸ‘‰ client
  • import app from './app' πŸ‘‰ client
  • require('./app') πŸ‘‰ server
  • Artist.findAll() πŸ‘‰ server
  • <script defer src="/bundle.js"></script> πŸ‘‰ public/client
    • Personally, I prefer to have the index.html file inside of the public directory and serve it from from /server/index.js using:
      // Static file-serving middleware
      app.use(express.static(path.join(__dirname, '..', 'public')))
    • Nonetheless, it boils down to preference. Juke has the index.html file in the client directory and serves it up from /server/index.js using:
      // Sends our index.html (the "single page" of our SPA)
      app.get('/', (req, res, next) => {
        res.sendFile(path.join(__dirname, '..', 'client', 'index.html'))
      })

Any other questions for morning review?

  • Question: When do you need to pass props into a react components constructor/super functions? Sometimes the solution code has it, sometimes it doesn't.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment