-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (28 loc) · 912 Bytes
/
index.js
File metadata and controls
30 lines (28 loc) · 912 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
28
29
30
/* eslint-env node, es2017 */
'use strict';
exports.Handler = function (
cookieOptions = {},
cookieRegex = /^cookie_/,
redirect = true) {
return function(
cookieOptions,
cookieRegex,
redirect,
request,
h ) {
if (request.method === "post") {
for(const k in request.payload) {
if (k.match(cookieRegex)) {
const cookieName = k.replace(cookieRegex,"");
const cookieValue = request.payload[k];
request.log(["debug"], `Setting ${cookieName} to ${cookieValue}`);
h.state(cookieName,cookieValue, cookieOptions);
}
}
if(redirect) {
return h.redirect(request.url).takeover();
}
}
return h.continue;
}.bind(undefined, cookieOptions, cookieRegex, redirect);
};