rest-vir - v1.0.0
    Preparing search index...

    Function findDevServicePort

    • Use this to find a service's port number when started without a locked-in port. This allows a client (usually a website frontend) to find which port the server started on by scanning ports starting with the port defined in the service's serviceOrigin property.

      If the service has no port in its serviceOrigin property, this function throws an error.

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

      This is used in defineService if the findActiveDevPort option is set to true.

      Parameters

      • service: Readonly<
            SelectFrom<
                ServiceDefinition,
                { endpoints: true; serviceName: true; serviceOrigin: true },
            >,
        >
      • options: Readonly<Omit<FindPortOptions, "isValidResponse">> = {}

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

      undefined if the given service has no port in its service origin.

      import {findDevServicePort, defineService, AnyOrigin} from '@rest-vir/define-service';

      const myService = defineService({
      serviceName: 'my-service',
      serviceOrigin: 'https://localhost:3000',
      requiredClientOrigin: AnyOrigin,
      endpoints: {
      '/my-path': {
      methods: {
      [HttpMethod.Get]: true,
      },
      requestDataShape: undefined,
      responseDataShape: undefined,
      },
      },
      });

      const {origin} = await findDevServicePort(myService);

      Error If the max scan distance has been reached without finding a valid port.