Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!(res instanceof Object)) {
res = {code: 200, body: res};
}
else {
res = exports.parseResponse(req, res);
}
events.emit('beforeResponseStart', info, req, res);
events.emit('beforeResponseData', info, req, res, res.body || '');
if (flashmessages) {
res = flashmessages.updateResponse(req, res);
} else {
// set the baseURL cookie for the browser
var baseURL = utils.getBaseURL(req);
cookies.setResponseCookie(req, res, {
name: 'baseURL',
value : baseURL,
path : baseURL
});
}
req.response_received = true;
return res;
};
start = function (res) {
start_res = res;
events.emit('beforeResponseStart', info, req, res);
if (res.body) {
events.emit('beforeResponseData', info, req, res, res.body);
}
if (flashmessages) {
res = flashmessages.updateResponse(req, res);
} else {
// set the baseURL cookie for the browser
var baseURL = utils.getBaseURL(req);
cookies.setResponseCookie(req, res, {
name: 'baseURL',
value : baseURL,
path : baseURL
});
}
_start(res);
};
var _send = send;
exports.updateResponse = function (req, res) {
var messages = _.map(exports.getOutgoingMessages(req), function (val) {
delete val.outgoing;
delete val.incoming;
return val;
});
if (req.response_received) {
exports.setBrowserCookie(req, messages);
}
else {
cookies.setResponseCookie(req, res, {
name: '_duality_flash',
value: JSON.stringify(messages),
path: require('duality/core').getBaseURL(req) + '/'
});
}
return res;
};