Friday, 14 December 2018

Disappearing local variable.

Hey All, hopefully this is the appropriate place to post this long issue. So in our app, we have a simple middleware that adds some common cookies for all calls to our locals.app.use(function (req, res, next) { //set the locals app.locals.service_id = req.cookies.serviceID; next(); }); Very simple. For some reason, with one of our specific calls, that field is appearing undefined at random times.async function submitUploadAWS(req, res){ cl("Uploading AWS file"); const serviceId = req.app.locals.service_id; // Randomly undefined for occasional calls }}}The only really unique thing we are doing compared to other calls is using multer beforehand to help upload a file before we do our own work``` const multer = require('multer');const storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, 'uploads/') }, filename: function (req, file, cb) { cb(null, file.originalname) } }); const upload = multer({ storage: storage });app.route("/form/submitFileUploadAWS/:fieldId").post( upload.single('file'), form_controller.submitUploadAWS ); ```Does anyone know of any reasons that variable would be appearing undefined? it's not consistent (i think about 40 out of 120 calls or something) and could multer be a culprit? thanks for the help!

Submitted December 14, 2018 at 09:42PM by BillWagglesword

No comments:

Post a Comment