Skip to content

Create @fedify/fresh package for Fresh 2.0 integration #466

@dahlia

Description

@dahlia

Background

Fresh 2.0 has introduced significant changes to its middleware API and overall architecture. The current Fedify integration module @fedify/fedify/x/fresh was designed for Fresh 1.x and is incompatible with these changes. We need to create a new package that properly integrates with Fresh 2.0's updated middleware system.

Key changes in Fresh 2.0

  • Unified middleware signatures: Middleware now receives a single context object instead of (req, ctx) parameters
  • Request object location: The Request object is now accessed via ctx.req instead of being a separate parameter
  • Context consolidation: Various context interfaces (AppContext, LayoutContext, RouteContext) have been unified into a single Context interface
  • Simplified configuration: No more fresh.config.ts or fresh.gen.ts files
  • Vite integration: Fresh 2.0 uses Vite for development and build processes

Requirements

Package structure

  • Package name: @fedify/fresh
  • Target: Fresh 2.0+ compatibility
  • Release timeline: Aligned with Fedify 2.0 release

Middleware implementation

The new middleware should:

  • Follow Fresh 2.0's unified middleware signature pattern: (ctx: Context) => Response | Promise<Response>
  • Access the request via ctx.req instead of as a separate parameter
  • Properly integrate with Fresh's new context system
  • Support all existing Fedify federation features

API compatibility

  • Maintain feature parity with the current @fedify/fedify/x/fresh module
  • Adapt to Fresh 2.0's context-based approach
  • Ensure smooth migration path for existing users

Technical specifications

Middleware signature

// Fresh 1.x pattern (old)
export function federation(req: Request, ctx: FreshContext): Response | Promise<Response>

// Fresh 2.0 pattern (new)
export function federation(ctx: Context): Response | Promise<Response>

Context access patterns

  • Use ctx.req for request access
  • Use ctx.url for URL information
  • Use ctx.state for passing data between middlewares
  • Use ctx.params for route parameters

Tasks

  • Create new package structure for @fedify/fresh
  • Implement Fresh 2.0 compatible middleware
  • Update type definitions for Fresh 2.0 context
  • Migrate existing functionality from @fedify/fedify/x/fresh
  • Add comprehensive tests for Fresh 2.0 integration
  • Write migration guide from @fedify/fedify/x/fresh to @fedify/fresh
  • Update documentation with Fresh 2.0 examples
  • Ensure compatibility with Vite build process

References

Acceptance criteria

  • The package works seamlessly with Fresh 2.0
  • All existing Fedify federation features are supported
  • Type safety is maintained with proper TypeScript definitions
  • Documentation includes clear examples for Fresh 2.0
  • Migration path from the old module is documented
  • Tests pass for all federation scenarios in Fresh 2.0 environment

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions