JSPM

@nestjs-kitchen/proxy

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q60681F
  • License MIT

Provides an HTTP proxy functionality in the NestJS style.

Package Exports

  • @nestjs-kitchen/proxy

Readme

@nestjs-kitchen/proxy

NPM Version NPM License codecov

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