Skip to content
This repository has been archived by the owner. It is now read-only.
[Migrated to nestcloud repository]A gateway module for nestcloud
TypeScript JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
.eslintrc.js
.gitignore
.npmignore
.prettierrc
README.md
index.d.ts
index.js
index.ts.js
package.json
tsconfig.json
tslint.json
yarn.lock

README.md

Nest Logo

Description

A component of nestcloud. NestCloud is a nest framework micro-service solution.

中文文档

A gateway for nestcloud.

Notification

You should not use body parser middleware when use this module or the post request will hang.

Quick Start

Register Module

import { Module } from '@nestjs/common';
import { GatewayModule } from "@nestcloud/gateway";

@Module({
    imports: [
        GatewayModule.register({ 
            routes: [
                {
                    id: 'user',
                    uri: 'lb://nestcloud-user-service'
                },
                {
                    id: 'pay',
                    uri: 'https://example.com/pay'
                }
            ] 
        }),
    ]
})
export class AppModule {
}

Or dependency @nestcloud/boot module.

import { Module } from '@nestjs/common';
import { NEST_BOOT } from '@nestcloud/common';
import { GatewayModule } from "@nestcloud/gateway";

@Module({
    imports: [
        GatewayModule.register({dependencies: [NEST_BOOT]}),
    ]
})
export class AppModule {
}

bootstrap.yaml

gateway:
  routes:
    - id: user
      uri: lb://nestcloud-user-service
    - id: pay
      uri: https://example.com/pay

Controller

import { All, Controller, Param, Req, Res } from "@nestjs/common";
import { Request, Response } from 'express';
import { Gateway, InjectGateway } from "@nestcloud/gateway";

@Controller('/gateway/:service')
export class GatewayController {
    constructor(
        @InjectGateway() private readonly gateway: Gateway,
    ) {
    }

    @All()
    do(@Req() req: Request, @Res() res: Response, @Param('service') id) {
        this.gateway.forward(req, res, id);
    }
}

TODO

filter support

Stay in touch

License

NestCloud is MIT licensed.

You can’t perform that action at this time.