Repository: parcel-bundler/parcel
File: packages/reporters/dev-server/src/Server.js (JavaScript)

Code before:
        this.options.inputFS,
        this.options.projectRoot,
        req,
        res,
        () => this.send404(req, res),
      );
    } else if (pathname.startsWith(this.rootPath)) {
      // Otherwise, serve the file from the dist folder
      req.url =
        this.rootPath === '/' ? pathname : pathname.slice(this.rootPath.length);
      return this.serveDist(req, res, () => this.sendIndex(req, res));
    } else {
      return this.send404(req, res);
    }
  }

  sendIndex(req: Request, res: Response) {
    if (this.bundleGraph) {
      // If the main asset is an HTML file, serve it
      let htmlBundleFilePaths = [];
      this.bundleGraph.traverseBundles(bundle => {
        if (bundle.type !== 'html' || !bundle.isEntry) {
          return;
        }

        htmlBundleFilePaths.push(bundle.filePath);
      });

      let indexFilePath =
        htmlBundleFilePaths.length > 1
          ? htmlBundleFilePaths
              .sort((a, b) => {
                return a.length - b.length;
              })
              .find(f => {
                return path.basename(f).startsWith('index');
              })
          : htmlBundleFilePaths[0];
      if (indexFilePath) {
        req.url = `/${path.relative(
          this.options.distDir,
          nullthrows(indexFilePath),
        )}`;

        this.serveDist(req, res, () => this.send404(req, res));
      } else {
        this.send404(req, res);
      }
    } else {
      this.send404(req, res);
    }

Review comment (suggestion):
```suggestion
        if (bundle.type === 'html' && bundle.isEntry) {
          htmlBundleFilePaths.push(bundle.filePath);
        }
```

Code after:
        this.options.projectRoot,
        req,
        res,
        () => this.send404(req, res),
      );
    } else if (pathname.startsWith(this.rootPath)) {
      // Otherwise, serve the file from the dist folder
      req.url =
        this.rootPath === '/' ? pathname : pathname.slice(this.rootPath.length);
      return this.serveDist(req, res, () => this.sendIndex(req, res));
    } else {
      return this.send404(req, res);
    }
  }

  sendIndex(req: Request, res: Response) {
    if (this.bundleGraph) {
      // If the main asset is an HTML file, serve it
      let htmlBundleFilePaths = [];
      this.bundleGraph.traverseBundles(bundle => {
        if (bundle.type === 'html' && bundle.isEntry) {
          htmlBundleFilePaths.push(bundle.filePath);
        }
      });

      let indexFilePath =
        htmlBundleFilePaths.length > 1
          ? htmlBundleFilePaths
              .sort((a, b) => {
                let lengthDiff = a.length - b.length;
                if (lengthDiff === 0) {
                  return a.localeCompare(b);
                } else {
                  return lengthDiff;
                }
              })
              .find(f => {
                return path.basename(f).startsWith('index');
              })
          : htmlBundleFilePaths[0];
      if (indexFilePath) {
        req.url = `/${path.relative(this.options.distDir, indexFilePath)}`;

        this.serveDist(req, res, () => this.send404(req, res));
      } else {
        this.send404(req, res);
      }
    } else {
      this.send404(req, res);
    }
  }