const getData = (req, res, url) => {
getDataDb(url.query, (err, result) => {
if (err) handleError(err, res);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(result));
});
};
const getDataAll = (req, res, url) => {
getDataAllDb(url.query, (err, result) => {
if (err) handleError(err, res);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(result));
});
};
const postData = (req, res, url) => {
console.log('in postData handler.');
// console.log('postdata urlobject is ', url);
postDataDb(url.query, (err, result) => {
if (err) handleError(err, res);
res.writeHead(200, { 'Content-Type': 'application/javascript' });
res.end(result);
});
};
Is the same as:
const query = (req, res, url, queryFunction) => {
queryFunction(url.query, (err, result) => {
if (err) return handleError(err, res);
res.writeHead(200, { 'Content-Type': 'application/javascript' });
res.end(JSON.stringify(result));
});
};
const getData = (req, res, url) => query(req, res, url, getDataDb);
const getDataAll = (req, res, url) => query(req, res, url, getDataAllDb);
const postData = (req, res, url) => query(req, res, url, postDataDb);
Is the same as: