我是一个新手,正在尝试使用Firebase函数与实时数据库(模拟器套件)一起使用。但是当我尝试使用Firebase函数设置数据库中的值时,它会出现错误并且无法将该值设置到数据库中。
错误:
17:33:14
I
function[us-central1-textToLength]
[2021-11-05T12:03:14.194Z] @firebase/database: FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets. Trying anyway.
17:34:18
I
function[us-central1-textToLength]
[2021-11-05T12:04:18.762Z] @firebase/database: FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets. Trying anyway.
17:35:06
I
function[us-central1-textToLength]
[2021-11-05T12:05:06.473Z] @firebase/database: FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets. Trying anyway.
17:35:54
I
function[us-central1-textToLength]
[2021-11-05T12:05:54.409Z] @firebase/database: FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets. Trying anyway.
Firebase函数代码:
const functions = require('firebase-functions');
var admin = require("firebase-admin");
admin.initializeApp();
var database = admin.database();
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
exports.textToLength = functions.https.onRequest((request, response) => {
var tex = request.query.text;
var textLength = tex.length;
console.log(textLength);
database.ref().child('test').set("op");
response.send(String(textLength));
});
依赖项:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "14"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1",
"@firebase/database-compat": "0.1.2"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}
已安装的npm软件包
+-- @firebase/app-compat@0.1.7
| +-- @firebase/app@0.7.6
| | +-- @firebase/component@0.5.8
| | | +-- @firebase/util@1.4.1 deduped
| | | `-- tslib@2.3.1 deduped
| | +-- @firebase/logger@0.3.1
| | | `-- tslib@2.3.1 deduped
| | +-- @firebase/util@1.4.1
| | | `-- tslib@2.3.1 deduped
| | `-- tslib@2.3.1 deduped
| +-- @firebase/component@0.5.8
| | +-- @firebase/util@1.4.1 deduped
| | `-- tslib@2.3.1 deduped
| +-- @firebase/logger@0.3.1
| | `-- tslib@2.3.1 deduped
| +-- @firebase/util@1.4.1
| | `-- tslib@2.3.1 deduped
| `-- tslib@2.3.1
+-- @firebase/database-compat@0.1.2
| +-- @firebase/component@0.5.7
| | +-- @firebase/util@1.4.0 deduped
| | `-- tslib@2.3.1 deduped
| +-- @firebase/database@0.12.2
| | +-- @firebase/auth-interop-types@0.1.6
| | +-- @firebase/component@0.5.7 deduped
| | +-- @firebase/logger@0.3.0 deduped
| | +-- @firebase/util@1.4.0 deduped
| | +-- faye-websocket@0.11.4
| | | `-- websocket-driver@0.7.4
| | | +-- http-parser-js@0.5.3
| | | +-- safe-buffer@5.2.1 deduped
| | | `-- websocket-extensions@0.1.4
| | `-- tslib@2.3.1 deduped
| +-- @firebase/database-types@0.9.1
| | +-- @firebase/app-types@0.7.0
| | `-- @firebase/util@1.4.0 deduped
| +-- @firebase/logger@0.3.0
| | `-- tslib@2.3.1 deduped
| +-- @firebase/util@1.4.0
| | `-- tslib@2.3.1 deduped
| `-- tslib@2.3.1 deduped
`-- firebase-admin@10.0.0
+-- @firebase/database-compat@0.1.2 deduped
+-- @firebase/database-types@0.7.3
| `-- @firebase/app-types@0.6.3
+-- @google-cloud/firestore@4.15.1
| +-- fast-deep-equal@3.1.3
| +-- functional-red-black-tree@1.0.1
| +-- google-gax@2.28.0