Skip to content

Commit 206d05b

Browse files
committed
Cookie の利用セクションを更新
1 parent b40a86a commit 206d05b

File tree

9 files changed

+944
-134
lines changed

9 files changed

+944
-134
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import express from "express";
2+
import cookieParser from "cookie-parser";
3+
4+
const app = express();
5+
app.use(cookieParser());
6+
7+
app.get("/", (request, response) => {
8+
// Cookieの値は文字列なので数値に変換が必要
9+
const count = Number.parseInt(request.cookies.count) || 0;
10+
const newCount = count + 1;
11+
// 変更後の値をレスポンスヘッダに乗せる
12+
response.cookie("count", newCount.toString());
13+
response.send(`${newCount}回目のアクセスですね。`);
14+
});
15+
16+
app.listen(3000);

0 commit comments

Comments
 (0)