MCPcopy Create free account
hub / github.com/vercel/vercel / delegateToService

Method delegateToService

packages/cli/src/util/dev/server.ts:1551–1662  ·  view source on GitHub ↗
(
    req: http.IncomingMessage,
    res: http.ServerResponse,
    requestId: string,
    matchedRoute: RouteWithSrc & { destination: ServiceDestination },
    vercelConfig: VercelConfig,
    requestTransforms?: Transform[],
    responseTransforms?: Transform[]
  )

Source from the content-addressed store, hash-verified

1549 }
1550
1551 private async delegateToService(
1552 req: http.IncomingMessage,
1553 res: http.ServerResponse,
1554 requestId: string,
1555 matchedRoute: RouteWithSrc & { destination: ServiceDestination },
1556 vercelConfig: VercelConfig,
1557 requestTransforms?: Transform[],
1558 responseTransforms?: Transform[]
1559 ): Promise<void> {
1560 const { debug } = output;
1561 const { service: serviceName, path: destPath } = matchedRoute.destination;
1562
1563 const origin = this.orchestrator?.getServiceOrigin(serviceName);
1564 if (!origin) {
1565 output.error(
1566 `Cannot route to service ${cmd(serviceName)}: it is not running.`
1567 );
1568 await this.sendError(
1569 req,
1570 res,
1571 requestId,
1572 'FUNCTION_INVOCATION_FAILED',
1573 502
1574 );
1575 return;
1576 }
1577
1578 // Resolve lookup path for the service's route table
1579 const parsed = url.parse(req.url || '/');
1580 const originalPathname = parsed.pathname || '/';
1581
1582 let lookupPath = originalPathname;
1583 if (typeof destPath === 'string' && matchedRoute.src) {
1584 const keys: string[] = [];
1585 const matcher = PCRE(
1586 `%${matchedRoute.src}%${this.isCaseSensitive() ? '' : 'i'}`,
1587 keys
1588 );
1589 const match =
1590 matcher.exec(originalPathname) ||
1591 matcher.exec(originalPathname.substring(1));
1592 lookupPath = match
1593 ? resolveRouteParameters(destPath, match, keys)
1594 : destPath;
1595 }
1596
1597 const serviceRoutes = this.getServiceRouteTable(serviceName);
1598 const proxyHeaders = this.getProxyHeaders(req, requestId, false);
1599
1600 const requestTransformsToApply: Transform[] = [
1601 ...(requestTransforms ?? []),
1602 ];
1603 let responseTransformsToApply = responseTransforms;
1604
1605 if (serviceRoutes.length > 0) {
1606 const serviceResult = await devRouter(
1607 `${lookupPath}${parsed.search || ''}`,
1608 req.method,

Callers 1

DevServerClass · 0.95

Calls 15

sendErrorMethod · 0.95
isCaseSensitiveMethod · 0.95
getServiceRouteTableMethod · 0.95
getProxyHeadersMethod · 0.95
sendRedirectMethod · 0.95
prepareTransformsMethod · 0.95
setResponseHeadersMethod · 0.95
resolveRouteParametersFunction · 0.90
devRouterFunction · 0.90
cmdFunction · 0.85
proxyPassFunction · 0.85
getServiceOriginMethod · 0.80

Tested by

no test coverage detected