将 CORS 标头添加到 Firebase Mailchimp 扩展

问题描述 投票:0回答:0

我有一个 firebase 应用程序(它是一个简单的网站),我试图用它通过一个简单的订阅输入区域捕获电子邮件,我希望这些电子邮件进入 mailchimp。这看起来很简单,但事实证明这是一件非常复杂的事情 - 也许我错过了一些东西。

我添加了一个 Firebase Mailchimp 扩展,并且我在我的 Firebase 应用程序中像这样调用该扩展:

import { getFunctions, httpsCallable } from "@firebase/functions";
import { initializeApp } from '@firebase/app';

export default function Newsletter() {
  const [email_address, setEmail_Address] = useState("");
  const [successMessage, setSuccessMessage] = useState(false);

  const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => {
    setEmail_Address(e.target.value);
    setSuccessMessage(false);
  };

  const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
    e.preventDefault();


    const data = {
      email: email_address,
      uid: Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15),
    };

    const app = initializeApp({
      apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
      authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
      projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
    });
    
    const functions = getFunctions(app);
    const addUserToList = httpsCallable(functions, 'ext-mailchimp-firebase-sync-addUserToList');
    addUserToList(data)
      .then((result) => {
        // Read result of the Cloud Function.
        //console.log(result.data);
        if (result.data) {
          setEmail_Address("");
          setSuccessMessage(true);
        }
      })
      .catch((error) => {
        // Getting the Error details.
        console.log(error);
      });

但是我收到以下错误:

Access to fetch at 'https://us-central1-epoch-main-1.cloudfunctions.net/ext-mailchimp-firebase-sync-addUserToList' from origin 'https://www.epoch.blue' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

听起来我需要在 Firebase Mailchimp 扩展中设置 CORS 策略,但我不知道该怎么做。有谁知道吗

firebase function cors mailchimp
© www.soinside.com 2019 - 2024. All rights reserved.