материал, который я использовал
- Firebase (облако-firestore)
- Javascript
- windows 10
Что я сделал?
Я пытался получить доступ с локального компьютера, но это не сработало.
Это ошибка в консоли
functions: ReferenceError: err is not defined
at exports.createScreams.functions.https.onRequest (C:\Users\taiga\Github\React2\Full-stack-app\socialape-functions\functions\index.js:59:19)
at runFunction (C:\Users\taiga\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:570:20)
at C:\Users\taiga\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:545:19
at Generator.next (<anonymous>)
at C:\Users\taiga\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:8:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\taiga\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:4:12)
at runFunction (C:\Users\taiga\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:542:12)
at C:\Users\taiga\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:569:15
at Generator.next (<anonymous>) ! Your function was killed because it raised an unhandled error.
индекс. js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp({ credential: admin.credential.applicationDefault() });
const firestore = admin.firestore();
firestore.settings({ignoreUndefinedProperties:true});
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello world");
});
exports.getScreams = functions.https.onRequest((req, res) => {
admin.firestore().collection('screams').get()
.then(data => {
let screams
data.docs.forEach(doc => {
screams.push(doc.data());
});
return res.json(screams);
})
.catch((err) => console.error(err));
});
exports.createScreams = functions.https.onRequest((req, res) => {
// if(req.method !== 'post') {
// return res.status(400).json({ error: 'method not allowed '})
// }
const newScreams = {
body: req.body,
userHandle: req.userHandle,
createdAt: admin.firestore.Timestamp.fromDate(new Date())
};
admin
.firestore()
.collection('screams')
.add(newScreams)
.then(doc => {
res.json({Message: `document ${doc.id} created successfully`});
})
.catch((err) => {
res.status(500).json({ error: 'something went wrong'});
});
console.error(err);
});
Кто-нибудь знает эту ошибку?