Skip to content

feat: middleware with polyglot support #27

@hulxv

Description

@hulxv

Description

Implement middleware support in MetaSSR to allow developers to intercept and modify requests and responses during the server-side rendering (SSR) process. This feature would enable custom logic to be applied at various points in the request lifecycle, such as authentication, logging, caching, or request transformation.

Polyglot Programming Support

MetaSSR will leverage the Metacall polyglot runtime, allowing middleware to be written in various programming languages like Python, JavaScript, or Ruby. This means developers can define middleware in their preferred language and easily integrate it into their applications.

Example in Javascript:

// ./src/middlewares/logger.js
export function handler(req) {
    console.log(`[LOG_FROM_JS]: Request received at: ${new Date()}`);
}

Example in Python:

# ./src/middlewares/logger.py

def handler(req):
    print(f"[LOG_FROM_PY]: Request received at: {datetime.now()}")
  • Benefits:
    • Provides flexibility in handling requests, allowing for centralized control over functionalities like security, session management, and performance optimization.
    • Simplifies the addition of cross-cutting concerns, such as authentication or logging, without duplicating code across different routes or components.
    • Polyglot support allows developers to write middleware in multiple languages, making it adaptable for diverse use cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions