我用firebase-admin写了一个快递服务器。 我可以使所有的auth调用都起作用:创建,读取,验证令牌,但是当我尝试使用数据库时,它什么也没做。
这是我初始化firebase admin的方式:
var admin = require('firebase-admin');
var serviceAccount = require('./firebase.config.json');
admin.database.enableLogging(true)
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: '"https://test-project.firebaseio.com"'
});
多数民众赞成在电话中:
admin.database().ref('users/test').once('value', (snap) => {
console.log('a')
}, (err) => {
console.log('a')
}).catch(err => {
console.log('a')
})
运行此操作无任何反应。 启用日志后,我得到了无尽的日志
[2018-10-29T10:07:50.526Z] @firebase/database: p:0: Making a connection attempt
index.cjs.js:60
[2018-10-29T10:07:50.527Z] @firebase/database: getToken() completed. Creating connection.
index.cjs.js:60
[2018-10-29T10:07:50.530Z] @firebase/database: c:0:0: Connection created
index.cjs.js:60
[2018-10-29T10:07:50.532Z] @firebase/database: c:0:0:0 Websocket connecting to wss://test-project.firebaseio.com"/.ws?v=5&ns=test-project
index.cjs.js:60
[2018-10-29T10:07:51.111Z] @firebase/database: c:0:0:0 WebSocket error. Closing connection.
index.cjs.js:60
[2018-10-29T10:07:51.112Z] @firebase/database: c:0:0:0 Error during WebSocket handshake: Unexpected response code: 400
index.cjs.js:60
[2018-10-29T10:07:51.112Z] @firebase/database: c:0:0:0 WebSocket is closing itself
[2018-10-29T10:07:51.114Z] @firebase/database: c:0:0: Realtime connection failed.
index.cjs.js:60
[2018-10-29T10:07:51.115Z] @firebase/database: c:0:0: Closing realtime connection.
index.cjs.js:60
[2018-10-29T10:07:51.116Z] @firebase/database: c:0:0: Shutting down all connections
index.cjs.js:60
[2018-10-29T10:07:51.118Z] @firebase/database: p:0: data client disconnected
index.cjs.js:60
[2018-10-29T10:07:51.119Z] @firebase/database: p:0: Trying to reconnect in 380.0931198129054ms
index.cjs.js:60
[2018-10-29T10:07:51.121Z] @firebase/database: 0: onDisconnectEvents
index.cjs.js:60
[2018-10-29T10:07:51.124Z] @firebase/database: c:0:0:0 Websocket connection was disconnected.
index.cjs.js:60
[2018-10-29T10:07:51.501Z] @firebase/database: p:0: Making a connection attempt
index.cjs.js:60
[2018-10-29T10:07:51.504Z] @firebase/database: getToken() completed. Creating connection.
index.cjs.js:60
[2018-10-29T10:07:51.505Z] @firebase/database: c:0:1: Connection created
任何人都知道如何使用firebase-admin进行数据库调用吗?