mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 11:15:14 +00:00
28 lines
569 B
JavaScript
28 lines
569 B
JavaScript
export function get(req, res) {
|
|
const cookies = req.headers.cookie
|
|
? req.headers.cookie.split(/,\s+/).reduce((cookies, cookie) => {
|
|
const [pair] = cookie.split('; ');
|
|
const [name, value] = pair.split('=');
|
|
cookies[name] = value;
|
|
return cookies;
|
|
}, {})
|
|
: {};
|
|
|
|
if (cookies.test) {
|
|
res.writeHead(200, {
|
|
'Content-Type': 'application/json'
|
|
});
|
|
|
|
res.end(JSON.stringify({
|
|
message: cookies.test
|
|
}));
|
|
} else {
|
|
res.writeHead(403, {
|
|
'Content-Type': 'application/json'
|
|
});
|
|
|
|
res.end(JSON.stringify({
|
|
message: 'unauthorized'
|
|
}));
|
|
}
|
|
} |