Fake Mirrors
    Preparing search index...

    Class RedisTargetRepository

    Redis-based target repository implementation.

    Depends:

    import { DIContainer } from '@famir/common'
    import { RedisTargetRepository } from '@famir/database'

    // Get container singleton
    const container = DIContainer.getInstance()

    // Register dependency in container
    RedisTargetRepository.register(container)
    import { DIContainer } from '@famir/common'
    import { TARGET_REPOSITORY, TargetRepository } from '@famir/domain'

    // Get container singleton
    const container = DIContainer.getInstance()

    // Register dependency in container
    RedisTargetRepository.register(container)

    // Resolve dependency from container
    const targetRepository = container.resolve<TargetRepository>(TARGET_REPOSITORY)

    // Read 'apex' target from 'httpbin' campaign
    const target = await targetRepository.read('httpbin', 'apex')
    console.log(target)

    Hierarchy (View Summary)

    Implements

    • Creates a new target.

      The target will be created in a disabled state (isEnabled = false). Use enable to activate it for traffic routing.

      Parameters

      • campaignId: string

        The ID of the campaign to create the target in.

      • targetId: string

        The new target ID to create.

      • accessLevel: "transparent" | "landing"

        The access level.

      • donorSecure: boolean

        The flag indicating if the donor server uses HTTPS.

      • donorSub: string

        The donor subdomain.

      • donorDomain: string

        The donor domain name.

      • donorPort: number

        The donor server port.

      • mirrorSecure: boolean

        The flag indicating if the mirror server uses HTTPS.

      • mirrorSub: string

        The mirror subdomain.

      • mirrorPort: number

        The mirror server port.

      • label: string

        The label for categorization.

      • connectTimeout: number

        The connection timeout in milliseconds.

      • simpleTimeout: number

        The simple request timeout in milliseconds.

      • streamTimeout: number

        The streaming request timeout in milliseconds.

      • headersSizeLimit: number

        The maximum headers size in bytes.

      • bodySizeLimit: number

        The maximum body size in bytes.

      • mainPage: string

        The custom main page content.

      • notFoundPage: string

        The custom not-found page content.

      • faviconIco: string

        The custom favicon.ico content.

      • robotsTxt: string

        The custom robots.txt content.

      • sitemapXml: string

        The custom sitemap.xml content.

      • allowWebSockets: boolean

        The flag indicating if WebSocket connections allowed.

      • lockSecret: string

        The campaign lock secret obtained from CampaignRepository.lock.

      Returns Promise<void>

      DatabaseError If the campaign does not exist.

      DatabaseError If the campaign is not locked.

      DatabaseError If the campaign lock secret does not match.

      DatabaseError If a target with the same ID already exists.

      DatabaseError If the target donor is already used.

      DatabaseError If the target mirror is already used.

      DatabaseError If the data validation fails.

    • Deletes the target by its ID.

      The target must be disabled before it can be deleted.

      Parameters

      • campaignId: string

        The ID of the campaign containing the target.

      • targetId: string

        The target ID to delete.

      • lockSecret: string

        The campaign lock secret obtained from CampaignRepository.lock.

      Returns Promise<void>

      DatabaseError If the campaign does not exist.

      DatabaseError If the campaign is not locked.

      DatabaseError If the campaign lock secret does not match.

      DatabaseError If the target does not exist.

      DatabaseError If the target is still enabled.

      DatabaseError If the data validation fails.

    • Disables the target, stopping traffic routing.

      When disabled, requests to the mirror hostname will not be proxied.

      Parameters

      • campaignId: string

        The ID of the campaign containing the target.

      • targetId: string

        The target ID to disable.

      • lockSecret: string

        The campaign lock secret obtained from CampaignRepository.lock.

      Returns Promise<void>

      DatabaseError If the campaign does not exist.

      DatabaseError If the campaign is not locked.

      DatabaseError If the campaign lock secret does not match.

      DatabaseError If the target does not exist.

      DatabaseError If the data validation fails.

    • Enables the target, making it available for traffic routing.

      When enabled, the mirror hostname becomes active and can be used for proxying requests to the donor server.

      Parameters

      • campaignId: string

        The ID of the campaign containing the target.

      • targetId: string

        The target ID to enable.

      • lockSecret: string

        The campaign lock secret obtained from CampaignRepository.lock.

      Returns Promise<void>

      DatabaseError If the campaign does not exist.

      DatabaseError If the campaign is not locked.

      DatabaseError If the campaign lock secret does not match.

      DatabaseError If the target does not exist.

      DatabaseError If the data validation fails.

    • Finds a target by its mirror hostname.

      This is the primary lookup method for routing incoming HTTP requests. Given a Host header from a request, it returns the corresponding target.

      Parameters

      • mirrorHost: string

        The mirror hostname to look up.

      Returns Promise<TargetModel | null>

      The target model, or null if no target matches the hostname.

      DatabaseError If the data validation fails.

    • Finds a full target by its mirror hostname.

      Parameters

      • mirrorHost: string

        The mirror hostname to look up.

      Returns Promise<FullTargetModel | null>

      The full target model, or null if no target matches the hostname.

      DatabaseError If the data validation fails.

    • Lists all targets for the campaign.

      Targets are ordered by creation time (oldest first).

      Parameters

      • campaignId: string

        The ID of the campaign to list targets for.

      Returns Promise<TargetModel[] | null>

      The array of target models, or null if the campaign does not exist.

      DatabaseError If the data validation fails.

    • Lists all full targets for the campaign.

      Targets are ordered by creation time (oldest first).

      Parameters

      • campaignId: string

        The ID of the campaign to list targets for.

      Returns Promise<FullTargetModel[] | null>

      The array of full target models, or null if the campaign does not exist.

      DatabaseError If the data validation fails.

    • Reads the target by its ID.

      Parameters

      • campaignId: string

        The ID of the campaign containing the target.

      • targetId: string

        The target ID to read.

      Returns Promise<TargetModel | null>

      The target model, or null if the target is not found.

      DatabaseError If the data validation fails.

    • Reads the full target by its ID.

      Parameters

      • campaignId: string

        The ID of the campaign containing the target.

      • targetId: string

        The target ID to read.

      Returns Promise<FullTargetModel | null>

      The full target model, or null if the target is not found.

      DatabaseError If the data validation fails.

    • Reads all target hosts across all campaigns.

      This method returns a dictionary mapping mirror hostnames to target links, used for fast routing lookups.

      Returns Promise<TargetHosts>

      The dictionary of target hosts and their links.

      DatabaseError If the data validation fails.

    • Updates the target specific fields.

      All update parameters are optional. Only provided fields will be updated.

      Parameters

      • campaignId: string

        The ID of the campaign containing the target.

      • targetId: string

        The target ID to update.

      • connectTimeout: number

        The connection timeout in milliseconds.

      • simpleTimeout: number

        The simple request timeout in milliseconds.

      • streamTimeout: number

        The streaming request timeout in milliseconds.

      • headersSizeLimit: number

        The maximum headers size in bytes.

      • bodySizeLimit: number

        The maximum body size in bytes.

      • mainPage: string

        The custom main page content.

      • notFoundPage: string

        The custom not-found page content.

      • faviconIco: string

        The custom favicon.ico content.

      • robotsTxt: string

        The custom robots.txt content.

      • sitemapXml: string

        The custom sitemap.xml content.

      • allowWebSockets: boolean

        The flag indicating if WebSocket connections allowed.

      • lockSecret: string

        The campaign lock secret obtained from CampaignRepository.lock.

      Returns Promise<void>

      DatabaseError If the campaign does not exist.

      DatabaseError If the campaign is not locked.

      DatabaseError If the campaign lock secret does not match.

      DatabaseError If the target does not exist.

      DatabaseError If the data validation fails.

    • Registers the target repository as a singleton in the DI container.

      Parameters

      • container: DIContainer

        The DI container to register in.

      Returns void