当我尝试在本地提供服务(在一切都正常部署之后)时,更新了nodejs和npm的版本后,我遇到了一个奇怪的问题。
详细信息: 当我尝试从angular6应用程序发送放置和/或删除请求到本地服务的fireabse时,控制台错误如下:
在以下位置访问XMLHttpRequest 'http://localhost:5000/PROJECT-NAME/us-central1/helloWorld' 来自来源“ http://localhost:4200”的信息已被CORS政策阻止: 预检中Access-Control-Allow-Methods不允许使用方法PUT 响应。
但是在发布/获取请求的情况下一切正常
版本:
NodeJS: 10.15.3
NPM : 6.4.1
firebase : 6.9.1
OS: macOS Mojave (10.14.4)
我在服务器中使用CORS;
const cors = require('cors')({ origin: true });
exports.helloWorld = functions.https.onRequest((req, res) => {
cors(req, res, () => {
res.send({message: "Hello from Firebase!"});
})
});
这是我的package.json文件
{
"name": "functions",
"scripts": {
"lint": "tslint --project tsconfig.json",
"build": "tsc --skipLibCheck",
"serve": "npm run build && firebase serve --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"main": "lib/index.js",
"dependencies": {
"@google-cloud/firestore": "^0.18.0",
"@sendgrid/mail": "^6.3.1",
"axios": "^0.18.0",
"core-util-is": "^1.0.2",
"cors": "^2.8.5",
"express": "^4.16.4",
"fetch-base64": "^2.1.2",
"firebase-admin": "^7.3.0",
"firebase-functions": "^2.3.1",
"image-to-base64": "^2.0.1",
"request": "^2.88.0",
"request-promise": "^4.2.2",
"string-similarity": "^3.0.0",
"stripe": "^6.26.1",
"twilio": "^3.29.1"
},
"devDependencies": {
"firebase-functions-test": "^0.1.6",
"tslint": "~5.8.0",
"typescript": "^3.3.3"
},
"private": true,
"engines": {
"node": "10"
}
}
答案 0 :(得分:0)
这是答案:
问题是在我提到的问题中更新firebase-tools之后出现的。 6.9.0和6.9.1的版本有此问题。 我只是将其降级到6.8.0,现在对我来说工作正常!