雲功能這是我調用的火力點返回響應500
'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.
嗨,謝謝你的回覆。當我直接打網址它的工作原理,但是當我使用一個XMLHttpRequest從一個靜態頁面我得到這個錯誤: '的XMLHttpRequest無法加載https://us-central1-idntt-baed5.cloudfunctions.net/date。請求的資源上沒有「Access-Control-Allow-Origin」標題。因此,原產地「https://idntt-baed5.firebaseapp.com」是不允許訪問。響應有HTTP狀態代碼500.' – Xpark