Midway JS Framework

website·Indexed 30 days ago

https://midway-next-site-lxxyx.vercel.app/

A TypeScript-based framework featuring Midway Serverless for deploying to Aliyun FC and Tencent Cloud SCF. It provides tools for migrating Express, Koa, and EggJS applications to serverless environments, supports a Hooks-based development model, and offers aggregate deployment to reduce cold starts.

Tokens
107K
Snippets
625
Records
726
Agent score
75%

What's inside Midway

  1. Overview of Midway Hooks Features

    Midway Hooks is a full-stack framework designed to unify frontend and backend development. Key features include:

    • Unified Development: Develop both frontend and backend code within a single src directory.
    • Zero API: Import backend functions directly into the frontend; these calls are automatically converted into API requests.
    • Modern Backend Development: Use React Hooks or Vue Composition API patterns to develop backend logic.
    • Performance: Fast startup times (under 3 seconds) powered by Vite.
    • Framework Support: Supports React, Vue, and other major frameworks.
    • Flexible Deployment: Can be deployed to traditional servers or Serverless environments.
    • Type Safety: Comprehensive TypeScript support.
  2. Overview of Midway Node.js Framework

    Midway is a progressive Node.js framework developed by Alibaba's Taobao frontend architecture team. Built with TypeScript, it supports multiple deployment scenarios including Web, Full-stack, Microservices, RPC, Socket, and Serverless. It is designed to provide a reliable and easy-to-use server-side development experience, combining both Object-Oriented and Functional programming paradigms.
  3. Overview of Midway Serverless

    Midway Serverless is a framework for building Node.js cloud functions (FaaS). It is designed to reduce maintenance costs in cloud-native environments and provides several key capabilities:

    • Cross-Cloud Deployment: Deploy the same codebase across multiple cloud providers to avoid vendor lock-in.
    • Unified Development: Integrated development solutions for frontend frameworks like React and Vue.
    • Code Reuse: Leverages dependency injection to make logic units reusable and composable for complex applications.
    • Legacy Migration: Allows seamless migration of traditional Egg.js, Koa, and Express.js applications to cloud functions via runtime extension capabilities.

    It can be used to build full-stack applications, standalone function services, RESTful APIs, or admin back-office projects.

  4. Overview of Midway Hooks features

    Midway Hooks is a full-stack development framework with the following key characteristics:

    • Full-stack Development: Develop both frontend and backend code within a single src directory.
    • 'Zero' API: Import backend functions directly into the frontend; these calls are automatically converted into API requests.
    • Backend Development via Hooks: Use React Hooks or Vue Composition API patterns to develop backend logic.
    • Performance: Fast startup speeds (under 3 seconds) powered by Vite.
    • Framework Support: Supports React, Vue, and other frameworks.
    • Deployment: Flexible deployment options for both traditional Servers and Serverless environments.
    • Type Safety: Comprehensive TypeScript support.
  5. Overview of Midway Decorator Management APIs

    Midway provides a set of standard decorator management APIs exported from the @midwayjs/decorator package. These APIs allow developers to bridge custom decorators with the dependency injection (DI) container for scanning and extension purposes.
    import { 
      saveModule, listModule, 
      saveClassMetadata, attachClassMetadata, getClassMetadata, 
      savePropertyDataToClass, attachPropertyDataToClass, getPropertyDataFromClass, listPropertyDataFromClass, 
      savePropertyMetadata, attachPropertyMetadata, getPropertyMetadata, 
      getProviderId, getObjectDefinition, getParamNames, clearAllModule 
    } from '@midwayjs/decorator';
  6. Overview of Midway.js Framework

    Midway.js is a Node.js framework designed for building API services and full-stack applications. It offers two primary development syntaxes: a Class-based syntax utilizing IoC (Inversion of Control) and Decorators for structured architecture, and a Function-based syntax using Hooks for rapid application development. The framework is designed to be progressive, scaling from basic setups to enterprise-level architectures.
  7. Overview of Midway logging system

    Midway uses a unified logging interface based on the winston library. It provides three primary types of loggers with different behaviors:

    • coreLogger: Used for framework and component level logs. Outputs to the console and midway-core.log. Errors are sent to common-error.log.
    • appLogger: Used for business logic logs. Outputs to the console and midway-app.log. Errors are sent to common-error.log.
    • ContextLogger: Used for request-link logs. It uses appLogger but adds request-specific context information (e.g., URL, protocol) and sends errors to common-error.log.
  8. Overview of Midway Hooks

    Midway Hooks provide a functional syntax (similar to React Hooks) that allows developers to access current request data and provide web services using functions. Unlike React Hooks, Midway Hooks are specifically used to access request context information and cannot be used to save state or execute side effects.
  9. Understand the RouterInfo data structure

    Each route in the route table is represented by a RouterInfo object. This object contains metadata about the route's path, method, handler, and associated middleware.
    export interface RouterInfo {
      prefix: string;            // Router prefix (e.g., from @Controller)
      routerName: string;         // Router alias name
      url: string | RegExp;       // Router path without prefix (e.g., from @Get)
      requestMethod: string;      // HTTP method (get, post, delete, etc.)
      method: string;             // The actual method name on the class
      description: string;        // Route description
      summary: string;            // Route summary
      handlerName: string;        // Equivalent to controllerId.method
      funcHandlerName: string;    // Handler name for @Func
      controllerId: string;      // IoC container key (providerId) of the controller
      middleware: any[];           // Route-level middleware
      controllerMiddleware: any[]; // Controller-level middleware
      requestMetadata: any[];     // Metadata from @Query, @Body, etc.
      responseMetadata: any[];    // Metadata from @SetHeader, @ContentType, etc.
    }
  10. Understand Serverless error handling behavior in Midway

    Midway implements specific error handling for Serverless scenarios to ensure security. When a function throws an error, the framework catches it and behaves differently based on the environment:

    • Non-production environments (e.g., NODE_ENV=local): The framework exposes the full error stack trace through the gateway.
    • Production environments: The framework returns a generic "Internal Server Error" message to the client, while the full error stack is still recorded in the logs.
    @ServerlessTrigger(//...)
    async invoke() {
        throw new Error('abc');
    }
  11. Understand RabbitMQ AMQP Core Concepts

    RabbitMQ is based on the Advanced Message Queuing Protocol (AMQP). The core components include:

    • Producer: The program that sends messages.
    • Broker: The message queue server entity, containing:
      • Exchange: Determines the rules for routing messages to specific queues.
      • Binding: Links an Exchange to a Queue based on routing rules.
      • Queue: The carrier where messages are stored.
    • Consumer: The program that receives and processes messages.
  12. Understand the Midway serverless.yml configuration structure

    Midway uses a description file (typically f.yml or serverless.yml) based on the Serverless Framework specification to describe function information within a repository. This allows for unified code that can be deployed across multiple platforms (e.g., Aliyun, Tencent, AWS). While Midway serverless v2 uses decorators to define functions, these decorators ultimately generate the functions section of the YAML structure.