async _processRequest()

in packages/metro/src/Server.js [447:499]


  async _processRequest(
    req: IncomingMessage,
    res: ServerResponse,
    next: (?Error) => mixed,
  ) {
    const originalUrl = req.url;
    req.url = this._config.server.rewriteRequestUrl(req.url);

    const urlObj = url.parse(req.url, true);
    const {host} = req.headers;
    debug(
      `Handling request: ${host ? 'http://' + host : ''}${req.url}` +
        (originalUrl !== req.url ? ` (rewritten from ${originalUrl})` : ''),
    );
    const formattedUrl = url.format({
      ...urlObj,
      host,
      protocol: 'http',
    });
    const pathname = urlObj.pathname || '';
    if (pathname.endsWith('.bundle')) {
      const options = this._parseOptions(formattedUrl);
      if (options.runtimeBytecodeVersion) {
        await this._processBytecodeBundleRequest(req, res, options);
      } else {
        await this._processBundleRequest(req, res, options);
      }

      if (this._serverOptions && this._serverOptions.onBundleBuilt) {
        this._serverOptions.onBundleBuilt(pathname);
      }
    } else if (pathname.endsWith('.map')) {
      // Chrome dev tools may need to access the source maps.
      res.setHeader('Access-Control-Allow-Origin', 'devtools://devtools');
      await this._processSourceMapRequest(
        req,
        res,
        this._parseOptions(formattedUrl),
      );
    } else if (pathname.endsWith('.assets')) {
      await this._processAssetsRequest(
        req,
        res,
        this._parseOptions(formattedUrl),
      );
    } else if (pathname.startsWith('/assets/') || pathname === '/assets') {
      await this._processSingleAssetRequest(req, res);
    } else if (pathname === '/symbolicate') {
      await this._symbolicate(req, res);
    } else {
      next();
    }
  }