gpt4 book ai didi

javascript - 用于 firebase 的 Cloud Functions 返回响应 500

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:12:20 25 4
gpt4 key购买 nike

这是我正在调用的函数

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const express = require('express');
const cors = require('cors')({origin: true});
const router = new express.Router();

router.use(cors);
router.get('*', (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*').status(200)
.send('Hello, Functions');
});

exports.date = functions.https.onRequest(router);

但是我收到了这个错误:

XMLHttpRequest cannot load https://us-central1-idntt-baed5.cloudfunctions.net/date. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://idntt-baed5.firebaseapp.com' is therefore not allowed access. The response had HTTP status code 500.

最佳答案

您要执行的操作的正确代码是:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

// Start writing Firebase Functions
// https://firebase.google.com/functions/write-firebase-functions

exports.date = functions.https.onRequest((request, response) => {
response.send("Hello, Functions");
})

现在你应该去喜欢这个https://us-central1-idntt-baed5.cloudfunctions.net/date .

并且您不允许使用 Access-Control-Allow-Origin

关于javascript - 用于 firebase 的 Cloud Functions 返回响应 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43602433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com