programing

사용자 지정 지역에 Firebase 배포(eu-central1)

lovejava 2023. 6. 23. 21:09

사용자 지정 지역에 Firebase 배포(eu-central1)

소방 기지 기능이 배치될 지역/지역을 지정할 수 있는 방법이 있습니까?

사실 나는 문서에서 그것에 대해 아무것도 찾지 못했고 내 기능은 항상 배포됩니다.us-central1하지만 나는 그것을 입고 싶습니다.eu-central1...

Firebase - Config - File에서 설정할 수 있습니까?

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

저도 cli 옵션을 살펴보았지만 아무것도 찾을 수 없었습니다.

파이어베이스 프로젝트 자체가 유럽 지역으로 올바르게 설정되어 있습니다.o

여기서 불을 뿜습니다.

업데이트(2018-07-25):

이제 Firebase에서 클라우드 기능에 대한 영역을 지정하고 코드에서 해당 영역을 지정한 후 변경 사항을 배포할 수 있습니다.예:

exports.myStorageFunction = functions
    .region('europe-west1')
    .storage
    .object()
    .onFinalize((object) => {
      // ...
    });

자세한 내용은 클라우드 기능 위치에 대한 Firebase 설명서(위의 스니펫을 참조)와 배포된 기능의 영역 수정을 참조하십시오.

문서에서: https://firebase.google.com/docs/functions/locations

이제 다음 지역에서 사용할 수 있습니다.

  • us-central1(아이오와)
  • us-east1(사우스캐롤라이나)
  • 유럽-서쪽1(벨기에)
  • 아시아-북동1(도쿄)

지역 변경 모범 사례

// before
const functions = require('firebase-functions');

exports.webhook = functions
    .https.onRequest((req, res) => {
            res.send("Hello");
    });

// after
const functions = require('firebase-functions');

exports.webhookEurope = functions
    .region('europe-west1')
    .https.onRequest((req, res) => {
            res.send("Hello");
    });

모든 기능에 동일한 사용자 지정 영역을 사용하려면 다음과 같은 작업을 수행합니다.

import * as functions from 'firebase-functions';

const regionalFunctions = functions.region('europe-west1');

export const helloWorld = regionalFunctions.https.onRequest((request, response) => {
 response.send("Hello from Firebase!");
});

export const helloWorld2 = regionalFunctions.https.onRequest((request, response) => {
 response.send("Hello from Firebase 2!");
});

지역에 배포된 Firebase 기능이 로컬 에뮬레이션에서도 작동하도록 하려면 클라이언트를 다음과 같이 초기화해야 합니다.

const functions = LOCAL ? firebase.app().functions(/*functionsRegion*/) :  
  firebase.app().functions(functionsRegion);

const fun = functions.httpsCallable('your_function_name');

즉, 코드가 동일하지 않습니다.에뮬레이트된 케이스에 영역을 추가하면 오류 없이 통화가 손실됩니다.

LOCAL백엔드가 클라우드에서 실행 중인지 로컬 에뮬레이션용으로 설정되었는지 여부를 알기 위해 만든 클라이언트 측 값입니다.

확실히, 이것은 파이어베이스가 다림질할 수 있는 코너 케이스입니까?

파이어베이스-공구 8.6.0,firebase7.16.1


Addendum:

위의 내용은 브라우저용입니다(설명되지 않았습니다)그 이후로 사용을 중단했습니다.httpsCallable온라인 연결이 필요하기 때문입니다.반면, Firebase 데이터베이스를 통한 인터페이스는 오프라인 친화적이므로 시스템이 더욱 강력해집니다.

새로운 Firebase 모듈식 SDK를 사용하는 경우 다음을 시도하십시오.

export const helloWorld = onRequest({ region: 'asia-southeast2' }, (request, response) => {
  logger.info('Hello logs!', { structuredData: true });
  response.send('Hello from Firebase!');
});

사용 가능한 지역 집합은 https://firebase.google.com/docs/functions/locations#supported_regions 에서 확인할 수 있습니다.

"rewrites": [
  {
    "source": "**",
    "run": {
      "serviceId": "<service id>",
      "region": "europe-west1"
    }
  }
]
},

언급URL : https://stackoverflow.com/questions/43569595/firebase-deploy-to-custom-region-eu-central1