All files / src/utils getIngressBackendByRegion.ts

100% Statements 8/8
100% Branches 7/7
100% Functions 1/1
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24      37x 32x     5x       5x 5x   1x   1x       3x      
import { Backend } from 'fastly:backend'
 
export function getIngressBackendByRegion(url: URL) {
  if (Backend.exists('fingerprint')) {
    return 'fingerprint'
  }
  // backward compat: region-named backends are deprecated, add a backend named 'fingerprint' instead
  console.warn(
    'Deprecated: region-named backends (api.fpjs.io, eu.api.fpjs.io, ap.api.fpjs.io) are deprecated. ' +
      "Please add a backend named 'fingerprint' pointing to your regional Fingerprint API host."
  )
  const region = url.searchParams.get('region')
  switch (region) {
    case 'eu':
      return 'eu.api.fpjs.io'
    case 'ap':
      return 'ap.api.fpjs.io'
    case null:
    case 'us':
    default:
      return 'api.fpjs.io'
  }
}