Package Exports
- @nestjs-kitchen/proxy
Readme
@nestjs-kitchen/proxy
Provides an HTTP proxy functionality in the NestJS style.
Feature
✅ Provides a NestJS-style API.
✅ Built on top of
http-proxy-middleware
✅ Compatible with both
@nestjs/platform-express
and@nestjs/platform-fastify
.
Install
$ npm install --save @nestjs-kitchen/proxy
Usage
Example
Register module:
// in app.module.ts
@Module({
imports: [
// ...
ProxyModule.register({
options: {
target: 'https://you.com/target/api',
changeOrigin: true,
agent: new Agent({ keepAlive: true })
}
})
// ...
],
controllers: [AppController],
providers: [],
})
export class AppModule {}
Apply Proxy in a Controller:
// in app.controller.ts
import { Controller, All, Post } from '@nestjs/common';
import { ProxyInterceptor } from '@nestjs-kitchen/proxy';
@UseInterceptors(ProxyInterceptor)
@Controller()
export class AppController {
@ProxyInterceptor.Use({
headers: { 'x-handler': 'ok' },
pathRewrite: { '^/proxy-api': '' }
})
@All('/proxy-api/*')
proxyApi() {
return true;
}
}
Options
See http-proxy-middleware#options
.
License
MIT License