stack/docs/src/middleware.ts
Madison 8fa56f898c
[docs][dashboard][stack-shared] Update docs to new apps (#996)
<!--

Make sure you've read the CONTRIBUTING.md guidelines:
https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md

-->

<img width="216" height="245" alt="image"
src="https://github.com/user-attachments/assets/f59f754f-b9d7-4e82-a552-8e407878eb01"
/>

<img width="940" height="564" alt="image"
src="https://github.com/user-attachments/assets/3218914e-5128-4cff-a183-29637adfb9f2"
/>



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Documentation**
* New "Apps" section with dedicated pages for API Keys, Emails, OAuth,
Permissions (RBAC), Orgs & Teams, Auth Providers, and Webhooks; API Keys
content moved into this section.
* New API Keys guide and updated overview content including an Apps grid
and app tiles.
  * Added redirects from old concept pages to new Apps pages.

* **Style**
* Sidebar now shows icons for docs links; improved hover animations and
tile styling across docs.

* **New Features**
  * App tile/card components added for displaying apps in docs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Introduces a new “Apps” docs section (API Keys, Emails, OAuth, RBAC,
Orgs & Teams, Webhooks), adds reusable app UI components, updates
navigation, and removes the old API Keys concept doc.
> 
> - **Docs**:
> - **Apps section**: Add `docs/content/docs/(guides)/apps/*` (API Keys,
Emails, OAuth, RBAC Permissions, Orgs & Teams, Webhooks) with icons and
examples; remove `concepts/api-keys.mdx` and update related links (e.g.,
JWT).
> - **Overview & Nav**: Insert AppGrid on `overview`, add “Apps” pages
to `meta.json`, add “Welcome” nav item, and refine “Guides” active-state
logic.
> - **Code examples**: Wire `docs/code-examples/index.ts` to load
`apps/api-keys` examples.
> - **UI/Components**:
> - Add `AppCard`/`AppGrid` in `docs/src/components/mdx/app-card.tsx`
and register in `mdx-components`.
> - Tweak homepage hover card styles (`iconHover.tsx`) and sidebar links
to support icons.
> - **Shared**:
> - Add `packages/stack-shared/src/apps/apps-ui.tsx` with `AppIcon` and
sizing constants; note UI export guidance in `stack-shared` `index.ts`.
> - **Styling/Infra**:
> - Add Tailwind `@source` in global CSS; minor layout/link icon
plumbing.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
2487b877aa. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
2025-11-12 15:45:30 -06:00

65 lines
2.1 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
// Redirect old concepts paths to new apps paths
const movedToApps = [
'api-keys',
'emails',
'oauth',
'orgs-and-teams',
'permissions',
'webhooks',
];
if (pathname.startsWith('/docs/concepts/')) {
const pageName = pathname.replace('/docs/concepts/', '');
if (movedToApps.includes(pageName)) {
const url = request.nextUrl.clone();
url.pathname = `/docs/apps/${pageName}`;
return NextResponse.redirect(url, 301); // 301 = permanent redirect
}
}
// Only apply to docs and api pages (not already .mdx requests)
// Match /docs, /docs/, /docs/... and /api, /api/, /api/...
const isDocsPath = pathname === '/docs' || pathname.startsWith('/docs/');
const isApiPath = pathname === '/api' || pathname.startsWith('/api/');
if ((isDocsPath || isApiPath) && !pathname.endsWith('.mdx')) {
const acceptHeader = request.headers.get('accept') || '';
// Parse Accept header by splitting on commas to properly handle MIME type ordering
const acceptTypes = acceptHeader.split(',').map(t => t.trim().split(';')[0]);
// Find the index of each MIME type in the Accept header
const plainIndex = acceptTypes.findIndex(
(t) => t === 'text/plain' || t === 'text/markdown'
);
const htmlIndex = acceptTypes.findIndex((t) => t === 'text/html');
// Prefer markdown if text/plain or text/markdown appears before text/html (or text/html doesn't exist)
const prefersMarkdown = plainIndex !== -1 && (htmlIndex === -1 || plainIndex < htmlIndex);
if (prefersMarkdown) {
// Rewrite to the LLM markdown endpoint
const url = request.nextUrl.clone();
url.pathname = `/llms.mdx${pathname.replace(/^\/(docs|api)/, '')}`;
// Preserve query parameters (platform, framework, etc.)
return NextResponse.rewrite(url);
}
}
return NextResponse.next();
}
export const config = {
matcher: [
'/docs/:path*',
'/api/:path*',
],
};