Witam,
hostuję swoje API Node.js/express w Firebase Functions. Jednak kiedy wyślę żądanie na ten adres, w logach wyświetla mi się błąd:
Możliwe, że błąd jest przez to, że do odbierania plików używam Multera. Kiedy odpalam kod lokalnie, wszystko działa.
Deklaracja punktu końcowego:
router.post('/checkErrors', upload.single('template'), checkErrors);
funkcja checkErrors():
const {TemplateHandler} = require('easy-template-x');
const handler = new TemplateHandler();
const checkErrors = async (req, res) => {
const template = req.file.buffer;
const data = JSON.parse(req.body.data);
const templateTags = await handler.parseTags(template);
const templateTagsNames = templateTags.map(({name}) => name);
//Znajdź brakujące wartości w Excel i je zidentyfikuj
const missingValues = [];
data.filter((row) => {
return !templateTagsNames.every((name) => Object.keys(row).includes(name));
}).forEach((row) => {
templateTagsNames.forEach((templateName) => {
if (!row.hasOwnProperty(templateName)) {
missingValues.push({fieldName: templateName, rowNum: row.rowNum + 1});
}
});
});
res.json({
errors: missingValues,
});
};
module.exports = checkErrors;