簡體   English   中英

使用/不使用模擬器時如何獲取 firebase 的當前 https 函數端點

[英]How to get the current https functions endpoint for firebase when using/not using emulator

我有一個 graphql api 在 firebase function 上運行,我大部分時間都在本地開發。

在我直接調用 firebase 函數之前,我會使用connectFunctionsEmulator function 有條件地連接到我的本地模擬器,當我使用getFunctions調用這些函數時,它會知道調用我的本地主機端點。

但是,我正在嘗試使用 Apollo 客戶端,我不確定如何確定本地模擬器何時連接以及何時連接,以及如何在調用 function 時確定絕對 url,就像 firebase 在我時所做的那樣使用 firebase 函數助手調用它。

我仔細查看了代碼,當我調用connectFunctionsEmulator function 時,它更新了一個名為functionsInstance.emulatorOrigin的變量。

這在輸入函數中不存在,但我仍然可以通過執行getFunctions().emulatorOrigin來訪問該值。

如果該值未設置為 null,則意味着 firebase 將與我的模擬器通話,而不是與實時端點通話。

function getGraphQLUri(): string {
  const functions = getFunctions();
  const app = getApp();

  const { projectId } = app.options;
  const { region } = functions;

  // emulatorOrigin is not defined in the typings but it exists
  // @ts-ignore
  const emulator = functions.emulatorOrigin;

  let url: string = "";

  if (emulator) {
    url = `${emulator}/${projectId}/${region}/graphql`;
  } else {
    url = `https://${region}-${projectId}.cloudfunctions.net/graphql`;
  }

  return url;
}

如果 Google 的某個人可以確認這種方法將來是否會繼續受到支持,我將不勝感激。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM