Skip to content

Commit

Permalink
cookie5 : 쇼핑몰 장바구니 기능 4
Browse files Browse the repository at this point in the history
  • Loading branch information
egoing committed Mar 25, 2016
1 parent 2c8eee6 commit 89934e9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app_cookie.js
Expand Up @@ -30,6 +30,23 @@ app.get('/cart/:id', function(req, res){
res.cookie('cart', cart);
res.redirect('/cart');
});
app.get('/cart', function(req, res){
var cart = req.cookies.cart;
if(!cart) {
res.rend('Empty!');
} else {
var output = '';
for(var id in cart){
output += `<li>${products[id].title} (${cart[id]})</li>`;
}
}
res.send(`
<h1>Cart</h1>
<ul>${output}</ul>
<a href="/products">Products List</a>
`);
});

app.get('/count', function(req, res){
if(req.cookies.count){
var count = parseInt(req.cookies.count);
Expand Down

0 comments on commit 89934e9

Please sign in to comment.