-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathok.js
More file actions
27 lines (19 loc) · 630 Bytes
/
ok.js
File metadata and controls
27 lines (19 loc) · 630 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module.exports = async function sendOK(data) {
const res = this.res;
const req = this.req;
if (!data) {
data = {};
}
if (typeof data === 'string') {
data = {message: data};
}
// ensure our models stay safe out there
data = sails.helpers.keepModelsSafe(data);
// set or remove cookies
data = sails.helpers.setOrRemoveCookies(data, res);
// handle CSRF tokens
data = await sails.helpers.updateCsrfAndExpiry(data, req);
const out = _.merge({success: true}, data);
res.status(200).json(out);
await sails.helpers.finalizeRequestLog(req, res, out);
};