All files / common get-base-url.ts

70% Statements 7/10
58.33% Branches 7/12
100% Functions 1/1
70% Lines 7/10

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 25 26 27      13x       13x       13x       13x       13x 13x     13x      
import { type CreateApiHandlerOptions } from "../type/create-api-handler-options"
 
export function getBaseUrl(options: CreateApiHandlerOptions) {
  let baseUrl = options.fallbackToPlayground
    ? "https://playground.projects.oryapis.com/"
    : ""
 
  Iif (process.env.ORY_SDK_URL) {
    baseUrl = process.env.ORY_SDK_URL
  }
 
  Iif (process.env.ORY_KRATOS_URL) {
    baseUrl = process.env.ORY_KRATOS_URL
  }
 
  Iif (process.env.ORY_SDK_URL && process.env.ORY_KRATOS_URL) {
    throw new Error("Only one of ORY_SDK_URL or ORY_KRATOS_URL can be set.")
  }
 
  Eif (options.apiBaseUrlOverride) {
    baseUrl = options.apiBaseUrlOverride
  }
 
  return baseUrl.replace(/\/$/, "")
}
export { CreateApiHandlerOptions }