firebase node.js 10部署错误.函数在加载用户代码时失败.无法初始化函数



我在将函数部署到firebase时不断收到这些错误,如下所示,它们告诉我在firebase函数状态下登录时查看日志-错误:函数已终止。建议操作:检查日志是否存在终止原因。无法初始化函数。

你知道我的问题在哪里吗?所有相关代码都低于

⚠functions[onUserImageChange(europe-west1(]:部署错误。函数在加载用户代码时失败。错误消息:错误:请检查您的函数日志以查看错误原因:https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs

⚠functions[onScreamDelete(europe-west1(]:部署错误。函数在加载用户代码时失败。错误消息:错误:请检查您的函数日志以查看错误原因:https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs

⚠functions[createNotificationOnComment(europe-west1(]:部署错误。函数在加载用户代码时失败。错误消息:错误:请检查您的函数日志以查看错误原因:https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs

⚠函数[api(us-central1(]:部署错误。函数在加载用户代码时失败。错误消息:错误:请检查您的函数日志以查看错误原因:https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs

⚠functions[createNotificationOnLike(europe-west1(]:部署错误。函数在加载用户代码时失败。错误消息:错误:请检查您的函数日志以查看错误原因:https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs

⚠functions[deleteNotificationOnUnLike(europe-west1(]:部署错误。函数在加载用户代码时失败。错误消息:错误:请检查您的函数日志以查看错误原因:https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs

/////////////index.js//////////

const functions = require('firebase-functions');
const app = require('express')();
const FBAuth = require('./util/fbAuth');

const { db } = require('./util/admin');


const firebase = require('firebase')
const config = require('./util/config')

firebase.initializeApp(config);

const { getAllScreams, 
postOneScream, 
getScream,
commentOnScream,
likeScream,
unlikeScream,
deleteScream
} = require('./handlers/screams');

const { signup, 
login, 
uploadImage,
addUserDetails,
getAuthenticatedUser,
getUserDetails,
markNotificationsRead,
} = require('./handlers/users');

//scream routes
app.get('/screams', getAllScreams);
app.post('/scream', FBAuth, postOneScream );
app.get('/scream/:screamId', getScream);
app.get('/scream/:screamId/like',FBAuth,likeScream);
app.get('/scream/:screamId/unlike',FBAuth,unlikeScream);
app.delete('/scream/:screamId/',FBAuth,deleteScream);

app.post('/scream/:screamId/comment', FBAuth,commentOnScream);

//users route
app.post('/signup', signup);
app.post('/login', login);
app.post('/user/image',FBAuth, uploadImage);
app.post('/user', FBAuth, addUserDetails);
app.get('/user', FBAuth, getAuthenticatedUser);
app.get('/user/:handle', getUserDetails);
app.post('/notifications', FBAuth, markNotificationsRead);


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


exports.createNotificationOnLike = functions
.region('europe-west1')
.firestore.document('likes/{id}')
.onCreate((snapshot) => {
return db
.doc(`/screams/${snapshot.data().screamId}`)
.get()
.then((doc) => {
if (
doc.exists &&
doc.data().userHandle !== snapshot.data().userHandle
) {
return db.doc(`/notifications/${snapshot.id}`).set({
createdAt: new Date().toISOString(),
recipient: doc.data().userHandle,
sender: snapshot.data().userHandle,
type: 'like',
read: false,
screamId: doc.id
});
}
})
.catch((err) => console.error(err));
});
exports.deleteNotificationOnUnLike = functions
.region('europe-west1')
.firestore.document('likes/{id}')
.onDelete((snapshot) => {
return db
.doc(`/notifications/${snapshot.id}`)
.delete()
.catch((err) => {
console.error(err);
return;
});
});
exports.createNotificationOnComment = functions
.region('europe-west1')
.firestore.document('comments/{id}')
.onCreate((snapshot) => {
return db
.doc(`/screams/${snapshot.data().screamId}`)
.get()
.then((doc) => {
if (
doc.exists &&
doc.data().userHandle !== snapshot.data().userHandle
) {
return db.doc(`/notifications/${snapshot.id}`).set({
createdAt: new Date().toISOString(),
recipient: doc.data().userHandle,
sender: snapshot.data().userHandle,
type: 'comment',
read: false,
screamId: doc.id
});
}
})
.catch((err) => {
console.error(err);
return;
});
});
exports.onUserImageChange = functions
.region('europe-west1')
.firestore.document('/users/{userId}')
.onUpdate((change) => {
console.log(change.before.data());
console.log(change.after.data());
if (change.before.data().imageUrl !== change.after.data().imageUrl) {
console.log('image has changed');
const batch = db.batch();
return db
.collection('screams')
.where('userHandle', '==', change.before.data().handle)
.get()
.then((data) => {
data.forEach((doc) => {
const scream = db.doc(`/screams/${doc.id}`);
batch.update(scream, { userImage: change.after.data().imageUrl });
});
return batch.commit();
});
} else return true;
});
exports.onScreamDelete = functions
.region('europe-west1')
.firestore.document('/screams/{screamId}')
.onDelete((snapshot, context) => {
const screamId = context.params.screamId;
const batch = db.batch();
return db
.collection('comments')
.where('screamId', '==', screamId)
.get()
.then((data) => {
data.forEach((doc) => {
batch.delete(db.doc(`/comments/${doc.id}`));
});
return db
.collection('likes')
.where('screamId', '==', screamId)
.get();
})
.then((data) => {
data.forEach((doc) => {
batch.delete(db.doc(`/likes/${doc.id}`));
});
return db
.collection('notifications')
.where('screamId', '==', screamId)
.get();
})
.then((data) => {
data.forEach((doc) => {
batch.delete(db.doc(`/notifications/${doc.id}`));
});
return batch.commit();
})
.catch((err) => console.error(err));
});














// // exports.createNotificationOnLike = functions.region("australia-southeast1")
// exports.createNotificationOnLike = functions.firestore.document('/likes/{id}')
// .onCreate((snapshot) => {
//     console.log(`this is snapshot.data ${snapshot.data}`)
// return db.doc(`/screams/${snapshot.data().screamId}`).get()
// .then(doc => {

//     console.log(`passed here 345g45g4g`)
//     if(doc.exists && doc.data().userHandle !== snapshot.data().userHandle){
//         console.log(`passed doc exists and req is not from own user 345g45g4g`)
//         console.log(`this is snapshot.data ${snapshot.data}`)
//         return db.doc(`/notifications/${snapshot.id}`).set({
//             createdAt: new Date().toISOString(),
//             recipient: doc.data().userHandle,
//             sender: snapshot.data().userHandle,
//             type: 'like',
//             read: false,
//             screamId: doc.id,
//         })
//     } else {
//        console.log('no document exists 3gg45g45g') 
//     }
// })
// .catch((err) => {
//     console.error(err);
// });





// exports.deleteNotificationOnUnLike = functions
// .firestore.document('/likes/{id}')
// .onDelete((snapshot) => {
// return db.doc(`/notifications/${snapshot.id}`)
// .onDelete()
// .catch((err) => {
//     console.error(err);
//     return
// })
// });






// exports.createNotificationOnComment = 
// functions.firestore.document('/comments/{id}')
// .onCreate((snapshot) => {

//     return db.doc(`/screams/${snapshot.data().screamId}`)
//     .get()
//     if(doc.exists && doc.data().userHandle !== snapshot.data().userHandle){
//         return db.doc(`/notifications/${snapshot.id}`).set({
//             createdAt: new Date().toISOString(),
//             recipient: doc.data().userHandle,
//             sender: snapshot.data().userHandle,
//             type: 'comment',
//             read: false,
//             screamId: doc.id,
//         });
//     }
// })
// .catch((err) => {
//     console.error(err);
//     return;
// });



// exports.onUserImageChange = functions.firestore.document('/users/{userId}')
// .onUpdate((change) => {
// console.log(change.before.data());
// console.log(change.after.data());

// if(change.before.data().imageUrl !== change.after.data().imageUrl){

//     console.log("image has changed");
// let batch = db.batch();
// return db.collection('screams').where('userHandle', '==', change.before.data().handle.get())
// .then((data) => {
//     data.forEach(doc => {
//         const scream = db.doc(`/screams/${doc.id}`);
//         batch.update(scream, {userImage: change.after.data().imageUrl});
//     })
//     return batch.commit
// })
// }
// })

// exports.onScreamDelete = functions.firestore.document('./screams/{screamId}')
// .onDelete((snapshot,context) => {
// const screamId = context.params.screamId;
// const batch = db.batch();

// //delete comments
// return db.collection('comments').where('screamId', "==", screamId).get()
// .then(data => {
//     data.forEach(doc => {
//         batch.delete(db.doc(`/comments/${doc.id}`));

//     })
//     return db.collection('likes').where('screamId', '==', screamId);
// })
// //delete likes
// return db.collection('likes').where('screamId', "==", screamId).get()
// .then(data => {
//     data.forEach(doc => {
//         batch.delete(db.doc(`/likes/${doc.id}`));

//     })
//     return db.collection('notifications').where('screamId', '==', screamId);
// })

// //delete  notifications
// return db.collection('notifications').where('screamId', "==", screamId).get()
// .then(data => {
//     data.forEach(doc => {
//         batch.delete(db.doc(`/notifications/${doc.id}`));

//     })
//     return batch.commit();
// })
// .catch((err)  =>{ console.error(err);
// })
// });



// });

////////////////////软件包.json/////////////////

{
"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": "10"
},
"dependencies": {
"busboy": "^0.3.1",
"firebase": "^7.17.1",
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.1"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}

尝试在控制台命令中键入firebase functions:log。它将显示更具体的错误

相关内容

  • 没有找到相关文章

最新更新