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

Code before:
        this.rootPath === '/' ? pathname : pathname.slice(this.rootPath.length);
      if (req.url[0] !== '/') {
        req.url = '/' + req.url;
      }
      return this.serveBundle(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
        .getBundles()
        .filter(bundle => path.posix.extname(bundle.name) === '.html')
        .map(bundle => {
          return `/${relativePath(
            this.options.distDir,
            bundle.filePath,
            false,
          )}`;
        });

      let indexFilePath = null;
      if (htmlBundleFilePaths.length === 1) {
        indexFilePath = htmlBundleFilePaths[0];
      } else {
        let bestMatch = null;
        for (let bundle of htmlBundleFilePaths) {
          let bundleDir = path.posix.dirname(bundle);
          let bundleDirSubdir = bundleDir === '/' ? bundleDir : bundleDir + '/';
          let withoutExtension = path.posix.basename(
            bundle,
            path.posix.extname(bundle),
          );
          let isIndex = withoutExtension === 'index';

          let matchesIsIndex = null;
          if (
            isIndex &&
            (req.url.startsWith(bundleDirSubdir) || req.url === bundleDir)
          ) {
            // bundle is /bar/index.html and (/bar or something inside of /bar/** was requested was requested)
            matchesIsIndex = true;
          } else if (req.url == path.posix.join(bundleDir, withoutExtension)) {
            // bundle is /bar/foo.html and /bar/foo was requested
            matchesIsIndex = false;
          }
          if (matchesIsIndex != null) {
            let depth = bundle.match(SLASH_REGEX)?.length ?? 0;

Review comment (suggestion):
Looks like previously it only looked at `req.url`, is there a reason why you added `originalUrl`?

I remember that we had problems with `req.originalUrl` in the past if you use [the proxy in front of the dev server](https://parceljs.org/features/development/#api-proxy).


Code after:
        this.rootPath === '/' ? pathname : pathname.slice(this.rootPath.length);
      if (req.url[0] !== '/') {
        req.url = '/' + req.url;
      }
      return this.serveBundle(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
        .getBundles()
        .filter(bundle => path.posix.extname(bundle.name) === '.html')
        .map(bundle => {
          return `/${relativePath(
            this.options.distDir,
            bundle.filePath,
            false,
          )}`;
        });

      let indexFilePath = null;
      let {pathname: reqURL} = url.parse(req.originalUrl || req.url);

      if (!reqURL) {
        reqURL = '/';
      }

      if (htmlBundleFilePaths.length === 1) {
        indexFilePath = htmlBundleFilePaths[0];
      } else {
        let bestMatch = null;
        for (let bundle of htmlBundleFilePaths) {
          let bundleDir = path.posix.dirname(bundle);
          let bundleDirSubdir = bundleDir === '/' ? bundleDir : bundleDir + '/';
          let withoutExtension = path.posix.basename(
            bundle,
            path.posix.extname(bundle),
          );
          let isIndex = withoutExtension === 'index';

          let matchesIsIndex = null;
          if (
            isIndex &&
            (reqURL.startsWith(bundleDirSubdir) || reqURL === bundleDir)
          ) {
            // bundle is /bar/index.html and (/bar or something inside of /bar/** was requested was requested)
            matchesIsIndex = true;