0.0.1 • Published 6 years ago
nest-gateway v0.0.1
Description
A component of nestcloud. NestCloud is a nest framework micro-service solution.
A gateway for nestcloud.
Quick Start
Register Module
import { Module } from '@nestjs/common';
import { GatewayModule } from "nest-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 nest-boot module.
import { Module } from '@nestjs/common';
import { NEST_BOOT } from 'nest-common';
import { GatewayModule } from "nest-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 "nest-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
- Author - NestCloud
License
NestCloud is MIT licensed.
0.0.1
6 years ago