javascript - 未为 Firebase 云功能启用 Cors
问题描述
我正在使用 cors npm 包来解决 cors 问题,但无济于事。这以前可以工作,但是当我切换到我的开发环境时,我不断收到此错误:
Access to fetch at 'https://carside.firebaseapp.com/sendsmstoconsumer' from origin 'https://carside.web.app' 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.
这就是我的函数代码的设置方式:
const functions = require('firebase-functions')
const express = require('express')
const app = express()
const accountSid = 'SECRET'
const authToken = 'SECRET'
const client = require('twilio')(accountSid, authToken)
const cors = require('cors')
// Enable cors for everything
// TODO: Re-enable cors at a later date
// src: https://www.npmjs.com/package/cors
app.use(cors())
app.post('/sendsmsverificationmessage', cors() ,(request, response) => {
client.verify.services('SECRET')
.verifications
.create({to: request.body.phone, channel: 'sms'})
.then(verification => {
response.send("Your verification code has been sent to your phone!" )
});
})
exports.app = functions.https.onRequest(app)
解决方案
推荐阅读
- javascript - 在映射数组时在我的“返回”中包含异步函数的结果
- keyman - keyman.setDefaultKeyboardForControl(Pelem, 键盘, languageCode); 函数不适用于 iframe 元素
- shopify - Shopify 商店上的 Klarna Express 按钮
- java - 如何从一个简单的java类调用javacc解析器并执行
- javascript - 防止同时插入大于最大值的值限制为小数
- c# - 每次我按“开始”时,C# autoclicker 都会崩溃
- json - 参数类型'列表
?不能分配给参数类型“列表” ' - mysql - MySQL 在进行数据库备份和迁移时挂断
- pointers - 如何在 C++ 中的 struct 中创建大小未知的动态分配数组
- mongodb - 如何将猫鼬初始化模型与对象数组一起使用