1
0
Fork 0

Parse body.

This commit is contained in:
Brian D 2024-12-03 20:40:16 -05:00
parent 0b43f42c85
commit 178e87239e
2 changed files with 37 additions and 29 deletions

View file

@ -36,17 +36,20 @@ const stickers = {
const requestListener = function (req, res) {
res.setHeader("Content-Type", "application/json");
const urlParts = req.url.split("/");
console.log(urlParts);
let body = '';
req.on('data', chunk => {
body += chunk.toString();
});
req.on('end', () => {
if (body) {
body = JSON.parse(body);
}
console.log('body', body);
});
console.log(urlParts);
switch (urlParts[1]) {
case "login":
res.writeHead(200);
res.end(JSON.stringify(users[body["username"]]));
break;
case "sticker":
if (!(urlParts[2] in stickers)) {
@ -72,6 +75,7 @@ const requestListener = function (req, res) {
res.writeHead(200);
res.end(JSON.stringify({nothing: 'here'}));
}
});
};
const server = http.createServer(requestListener);

View file

@ -21,10 +21,14 @@ const next = route.query.next;
function handleLogin({ valid }) {
if (!valid) {
console.log('Input is not valid.')
return;
}
sessionStore.login(username.value, username.value).then(() => {
console.log(`go to ${next}`)
router.push(next);
}).catch((error) => {
console.log(error);
});
}