gpt4 book ai didi

firebase - 对预检请求的响应未通过访问控制检查 : Redirect is not allowed for a preflight request

转载 作者:行者123 更新时间:2023-12-04 14:27:11 26 4
gpt4 key购买 nike

我在后端使用 vue 和 express + firebase 函数,但它一直给我这个错误。我部署了我的 firebase 函数并使用 localhost 来访问我的服务器。任何人都可以帮忙吗?谢谢!

from origin 'http://localhost:8081' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.



前端
        let updateWorkshop = Firebase.functions().httpsCallable('v3/update/workshop');
updateWorkshop()
.then(res => {
console.log(res);
commit('setInfoMsg', processResults (res.body.results))
commit('setError', null)
commit('setLoading', false)
}, err => {
console.log(err);
commit('setError', processResults (err.body.results))
commit('setLoading', false)
})

后端
const functions = require('firebase-functions');
const app = require('express')();
const cors = require('cors');
const colors = require('colors');

const UPDATE_WORKSHOP_DATE = require('./src/update-workshop');

// Automatically allow cross-origin requests
app.use(cors({ origin: true }));

const asyncMiddleware = fn => (req, res, next) => {
Promise.resolve(fn(req, res, next))
.catch((err) => {
console.error(err);
res.json(err)
})
.catch(next)
};

app.get('/v3/update/workshop', asyncMiddleware( async (req, res, next) => {
let results = await UPDATE_WORKSHOP_DATE.Run()
res.status(200).json({results: results})
}))

exports.api = functions.https.onRequest(app);

最佳答案

还需要将“api”添加到 url 中。

Firebase.functions().httpsCallable('api/v3/update/workshop');

关于firebase - 对预检请求的响应未通过访问控制检查 : Redirect is not allowed for a preflight request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57229663/

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