Skip to content

Commit 61bbdf2

Browse files
committed
Added UI for cookie info
1 parent 87d1fd1 commit 61bbdf2

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

client/src/App.jsx

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ const buildApiPath = (endpoint) => {
66

77
const [firstSegment] = window.location.pathname.split("/").filter(Boolean);
88
const basePath = firstSegment ? `/${firstSegment}` : "";
9-
const normalisedEndpoint = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
9+
const normalisedEndpoint = endpoint.startsWith("/")
10+
? endpoint
11+
: `/${endpoint}`;
1012
return `${basePath}${normalisedEndpoint}`;
1113
};
1214

1315
function App() {
1416
const [info, setInfo] = useState(null);
1517
const [loading, setLoading] = useState(true);
1618
const [error, setError] = useState(null);
19+
const [cookies, setCookies] = useState(null);
20+
const [cookiesLoading, setCookiesLoading] = useState(true);
21+
const [cookiesError, setCookiesError] = useState(null);
1722

1823
useEffect(() => {
1924
fetch(buildApiPath("/api/info"))
@@ -31,6 +36,23 @@ function App() {
3136
});
3237
}, []);
3338

39+
// Fetch cookies separately
40+
useEffect(() => {
41+
fetch(buildApiPath("/api/cookies"))
42+
.then((res) => {
43+
if (!res.ok) throw new Error("Network response was not ok");
44+
return res.json();
45+
})
46+
.then((data) => {
47+
setCookies(data);
48+
setCookiesLoading(false);
49+
})
50+
.catch((err) => {
51+
setCookiesError(err.message);
52+
setCookiesLoading(false);
53+
});
54+
}, []);
55+
3456
return (
3557
<>
3658
<h1>J26 Infra test and demo</h1>
@@ -67,6 +89,42 @@ function App() {
6789
</tbody>
6890
</table>
6991
)}
92+
<h2>Call /api/cookies</h2>
93+
{cookiesLoading && <p>Loading...</p>}
94+
{cookiesError && <p style={{ color: "red" }}>Error: {cookiesError}</p>}
95+
{cookies && Object.keys(cookies).length === 0 && (
96+
<p>No cookies present</p>
97+
)}
98+
{cookies && Object.keys(cookies).length > 0 && (
99+
<table style={{ borderCollapse: "collapse", marginTop: "1em" }}>
100+
<thead>
101+
<tr>
102+
<th style={{ border: "1px solid #ccc", padding: "8px" }}>Name</th>
103+
<th style={{ border: "1px solid #ccc", padding: "8px" }}>
104+
Value
105+
</th>
106+
</tr>
107+
</thead>
108+
<tbody>
109+
{Object.entries(cookies).map(([name, value]) => (
110+
<tr key={name}>
111+
<td
112+
style={{
113+
border: "1px solid #ccc",
114+
padding: "8px",
115+
fontWeight: "bold",
116+
}}
117+
>
118+
{name}
119+
</td>
120+
<td style={{ border: "1px solid #ccc", padding: "8px" }}>
121+
{String(value)}
122+
</td>
123+
</tr>
124+
))}
125+
</tbody>
126+
</table>
127+
)}
70128
</>
71129
);
72130
}

0 commit comments

Comments
 (0)