Przejdź do głównej zawartości

Session Test Documentation Page

Ta treść nie jest jeszcze dostępna w Twoim języku.

This page demonstrates session handling within Starlight documentation pages. Since Starlight pages are typically prerendered, we’ll show how to integrate dynamic session functionality.

Loading session data...

This Starlight page demonstrates several session concepts:

Since Starlight pages are prerendered by default, we use a React component that fetches session data from an API endpoint after the page loads:

// Fetch session data on component mount
useEffect(() => {
fetch('/api/session')
.then(res => res.json())
.then(data => setSessionData(data));
}, []);

The component communicates with an API endpoint at /api/session that handles:

  • GET: Retrieve current session information
  • POST: Store custom data in the session
  • DELETE: Clear the session

Sessions are persisted using HTTP-only cookies with these properties:

cookies.set('session_id', sessionId, {
path: '/',
maxAge: 60 * 60 * 24 * 30, // 30 days
httpOnly: true,
secure: true,
sameSite: 'lax'
});
FeatureStandard Astro PageStarlight Documentation
RenderingSSR (server-side)Prerendered (static)
Session AccessDirect in frontmatterVia API endpoints
Cookie HandlingAstro.cookiesClient-side fetch
Form HandlingNative HTML formsJavaScript/React
Database AccessDirect in pageVia API endpoints
  1. Visit Counter: Refresh this page and watch the visit count increase
  2. Custom Data: Enter some text and save it to the session
  3. Persistence: Navigate away and come back - your data persists
  4. Clear Session: Use the clear button to reset everything

To implement sessions in your own Starlight documentation:

  1. Create API endpoints for session management
  2. Use client-side components for dynamic content
  3. Implement proper error handling
  4. Consider caching strategies for performance
  5. Add session-based features like progress tracking

This test page demonstrates session functionality in Starlight. Visit the standard Astro test page to compare implementations.