express5-api-patterns

Implement Express 5 TypeScript patterns for HLS proxying, JWT cookie auth, and multi-instance routing.

37|6|Updated Oct 10, 2025
One-click install
npx skills add https://github.com/carrotwaxr/peek-stash-browser --skill express5-api-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: express5-api-patterns
Source: https://github.com/carrotwaxr/peek-stash-browser/tree/main/.claude/skills/express5-api-patterns
Command: npx skills add https://github.com/carrotwaxr/peek-stash-browser --skill express5-api-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill captures production-proven Express 5 patterns from the peek-stash-browser backend so developers can implement robust TypeScript route handlers, streaming proxies, authentication middleware, and database access without reimplementing core behavior or introducing subtle bugs.

Core Features & Use Cases

  • Async-safe handlers & error middleware: Uses Express 5's automatic promise rejection handling and provides AppError/NotFoundError shapes for consistent JSON error responses.
  • HLS proxying & playlist rewriting: Patterns for fetching HLS playlists, stripping apikeys, rewriting segment URLs to route through Peek, and streaming with AbortController and backpressure-aware pipelines.
  • Concurrency-limited HTTP proxy & connection pooling: Demonstrates keep-alive agents, queue-based concurrency slots, client-disconnect cleanup, and upstream timeout handling to protect Stash instances.
  • Multi-instance routing & Prisma integration: Shows resolving stashInstanceId per entity, safely retrieving instance credentials, and performing Prisma/SQLite queries for entity lookup.
  • JWT cookie auth & refresh semantics: Covers HTTP-only token cookies, silent refresh policy, dual cookie/Bearer token support, reverse-proxy header auth, and role-based middleware.
  • Use Case: Implement a scene streaming endpoint that proxies Stash HLS, rewrites playlists to remove API keys, enforces authentication and rate/connection limits, and forwards appropriate cache headers.

Quick Start

Generate Express 5 TypeScript route and middleware code to proxy HLS streams with JWT cookie authentication and Prisma-backed multi-instance routing for the peek-stash-browser backend.

Frequently Asked Questions about express5-api-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I proxy HLS streams in Express 5 without exposing upstream API keys?

Proxy HLS streams in Express 5 by fetching upstream playlists, stripping API keys from segment URLs, and rewriting those URLs to route through your backend. This pattern uses backpressure-aware streaming pipelines and AbortController to manage client disconnects safely.

Does Express 5 automatically handle async promise rejections in route handlers?

Yes, Express 5 automatically handles async promise rejections in route handlers, propagating errors to error middleware. You can use AppError and NotFoundError shapes to generate consistent JSON error responses without manually wrapping every async function.

How do I implement JWT cookie authentication with silent refresh in TypeScript?

Implement JWT cookie authentication by storing HTTP-only tokens in cookies, supporting dual cookie and Bearer token extraction, and applying a silent refresh policy. Role-based middleware validates tokens and manages refresh semantics seamlessly for backend routing.

What is the best way to limit proxy concurrency and handle backpressure when streaming media?

Limit proxy concurrency using keep-alive agents combined with queue-based concurrency slots to protect upstream instances. Handle streaming backpressure by utilizing backpressure-aware pipelines and cleaning up client connections with AbortController during upstream timeouts.

How do I route requests to multiple Stash instances using Prisma and SQLite?

Route requests to multiple Stash instances by resolving the target stashInstanceId per entity, safely retrieving instance credentials, and executing Prisma and SQLite database queries for entity lookup. This pattern ensures correct upstream routing for scene and media entities.

Can I use path-to-regexp v8 route conventions with Express 5 TypeScript middleware?

Yes, Express 5 uses path-to-regexp v8 route conventions, which you can leverage alongside strict TypeScript typings. This combination allows you to write robust route handlers and middleware that conform to the latest Express routing specifications.