Repository: expo/expo
File: packages/@expo/cli/src/start/server/metro/MetroBundlerDevServer.ts (TypeScript)

Code before:
    if (!options.isExporting) {
      const manifestMiddleware = await this.getManifestMiddlewareAsync(options);

      // Important that we noop source maps for context modules as soon as possible.
      prependMiddleware(middleware, new ContextModuleSourceMapsMiddleware().getHandler());

      // We need the manifest handler to be the first middleware to run so our
      // routes take precedence over static files. For example, the manifest is
      // served from '/' and if the user has an index.html file in their project
      // then the manifest handler will never run, the static middleware will run
      // and serve index.html instead of the manifest.
      // https://github.com/expo/expo/issues/13114
      prependMiddleware(middleware, manifestMiddleware.getHandler());

      middleware.use(
        new InterstitialPageMiddleware(this.projectRoot, {
          // TODO: Prevent this from becoming stale.
          scheme: options.location.scheme ?? null,
        }).getHandler()
      );
      middleware.use(
        new DevToolsPluginMiddleware(this.projectRoot, this.devToolsPluginManager).getHandler()
      );

      const deepLinkMiddleware = new RuntimeRedirectMiddleware(this.projectRoot, {
        getLocation: ({ runtime }) => {
          if (runtime === 'custom') {
            return this.urlCreator?.constructDevClientUrl();
          } else {
            return this.urlCreator?.constructUrl({
              scheme: 'exp',
            });
          }
        },
      });
      middleware.use(deepLinkMiddleware.getHandler());

      const serverRoot = getMetroServerRoot(this.projectRoot);

      const domComponentRenderer = createDomComponentsMiddleware(
        {
          metroRoot: serverRoot,
          projectRoot: this.projectRoot,
        },
        instanceMetroOptions
      );
      // Add support for DOM components.
      // TODO: Maybe put behind a flag for now?
      middleware.use(domComponentRenderer);

      middleware.use(

Review comment (suggestion):
note: There's potentially more that'll break with URL building, so this won't be sufficient potentially since it won't affect the `UrlCreator`. We can get to that separately though

Code after:
      resetCache: options.resetDevServer,
    };

    event('start', {
      mode,
      web: this.isTargetingWeb(),
      baseUrl,
      asyncRoutes,
      routerRoot: event.path(appDir),
      serverComponents: this.isReactServerComponentsEnabled,
      serverActions: isReactServerActionsOnlyEnabled,
      serverRendering: useServerRendering,
      apiRoutes: hasApiRoutes,
      exporting: !!options.isExporting,
    });

    const { metro, hmrServer, server, middleware, messageSocket } = await instantiateMetroAsync(
      this,
      parsedOptions,
      {
        isExporting: !!options.isExporting,
        exp,
      }
    );

    const protocol = server instanceof https.Server ? 'https' : 'http';

    // Required for symbolication:
    process.env.EXPO_DEV_SERVER_ORIGIN = `${protocol}://localhost:${options.port}`;

    if (!options.isExporting) {
      const manifestMiddleware = await this.getManifestMiddlewareAsync(options);

      // Important that we noop source maps for context modules as soon as possible.
      prependMiddleware(middleware, new ContextModuleSourceMapsMiddleware().getHandler());

      // We need the manifest handler to be the first middleware to run so our
      // routes take precedence over static files. For example, the manifest is
      // served from '/' and if the user has an index.html file in their project
      // then the manifest handler will never run, the static middleware will run
      // and serve index.html instead of the manifest.
      // https://github.com/expo/expo/issues/13114
      prependMiddleware(middleware, manifestMiddleware.getHandler());

      middleware.use(
        new InterstitialPageMiddleware(this.projectRoot, {
          // TODO: Prevent this from becoming stale.
          scheme: options.location.scheme ?? null,
        }).getHandler()
      );
      middleware.use(