function requestHandler(req, next) {
  // The URL() constructor returns a newly created URL object representing the URL defined by the parameters.
  const reqUrl = new URL(req.url);
  // path.normalize resolves '..' and '.' segments in sequential path segments
  // url.pathname: an initial '/' followed by the path of the URL not including the query string or fragment (or the empty string if there is no path).
  let reqPath = path.normalize(reqUrl.pathname);

  // when app opens, serve index-prod.html
  if (reqPath === '/') {
    reqPath = '/index-prod.html';
  }
  // path.basename returns the last portion of a path which includes filename we want to serve
  const reqFilename = path.basename(reqPath);
  // use fs module to read index-prod.html (reqPath) in dist folder
  fs.readFile(path.join(DIST_PATH, reqPath), (err, data) => {
    const mimeType = mime(reqFilename); // returns the file type
    // check if there is no error and file type is valid, pass on the info to the next middleware
    if (!err && mimeType !== null) {
      next({
        mimeType,
        charset: charset(mimeType),
        data
      });
    } else {
      console.error(err);
    }
  });
}
/* requestHandler
      servers index-prod.html when we access the root endpoint '/'
      read the file above and pass on an object includes mimeType, charset, and exisiting data read from the file 
*/
requestHandler
servers index-prod.html when we access the root endpoint '/'
read the file above and pass on an object includes mimeType, charset, and exisiting data read from the file
requestHandler servers index - prod . html when we access the root endpoint ' / ' read the file above and pass on an object includes mimeType charset and exisiting data read from the file
function requestHandler(req, next) {
  const reqUrl = new URL(req.url);
  let reqPath = path.normalize(reqUrl.pathname);
  if (reqPath === '/') {
    reqPath = '/index-prod.html';
  }
  const reqFilename = path.basename(reqPath);
  fs.readFile(path.join(DIST_PATH, reqPath), (err, data) => {
    const mimeType = mime(reqFilename); 
    if (!err && mimeType !== null) {
      next({
        mimeType,
        charset: charset(mimeType),
        data
      });
    } else {
      console.error(err);
    }
  });
}
function requestHandler ( req , next ) { const reqUrl = new URL ( req . url ) ; let reqPath = path . normalize ( reqUrl . pathname ) ; if ( reqPath === '/' ) { reqPath = '/index-prod.html' ; } const reqFilename = path . basename ( reqPath ) ; fs . readFile ( path . join ( DIST_PATH , reqPath ) , ( err , data ) => { const mimeType = mime ( reqFilename ) ; if ( ! err && mimeType !== null ) { next ( { mimeType , charset : charset ( mimeType ) , data } ) ; } else { console . error ( err ) ; } } ) ; }
requestHandler
servers index-prod.html when we access the root endpoint '/'
read the file above and pass on an object includes mimeType, charset, and exisiting data read from the file
requestHandler servers index - prod . html when we access the root endpoint ' / ' read the file above and pass on an object includes mimeType charset and exisiting data read from the file
// The URL() constructor returns a newly created URL object representing the URL defined by the parameters. // path.normalize resolves '..' and '.' segments in sequential path segments // url.pathname: an initial '/' followed by the path of the URL not including the query string or fragment (or the empty string if there is no path). // when app opens, serve index-prod.html // path.basename returns the last portion of a path which includes filename we want to serve // use fs module to read index-prod.html (reqPath) in dist folder // returns the file type // check if there is no error and file type is valid, pass on the info to the next middleware