rest-vir - v2.2.0
    Preparing search index...

    Function findDevServerPort

    • Use this to find an api's port number when its server was started without a locked-in port. The client (usually a website frontend) scans upward from the port in startOrigin, sending an OPTIONS request to the api's first endpoint until one responds with a matching restVirApiNameHeader.

      Note that the api given must have at least one endpoint defined for this function to work.

      Parameters

      Returns Promise<{ origin: string; port: number } | undefined>

      undefined if startOrigin has no port to start scanning from.

      import {
      HttpMethod,
      HttpStatus,
      defineApi,
      defineEndpoint,
      findDevServerPort,
      } from '@rest-vir/api';

      const myApi = defineApi({
      apiName: 'my-api',
      endpoints: [
      defineEndpoint({
      path: '/my-path',
      requests: {
      [HttpMethod.Get]: {
      responses: {
      [HttpStatus.Ok]: {
      responseData: undefined,
      },
      },
      },
      },
      }),
      ],
      webSockets: [],
      });

      const {origin} = await findDevServerPort(myApi, {
      startOrigin: 'https://localhost:3000',
      });

      Error If the max scan distance or timeout is reached without finding a valid port.