Zhiyuan Zhang
Zhiyuan Zhang

Reputation: 41

issue with nestjs + fastify-http-proxy

I am trying to build a Nestjs api proxy (pass through). I found this package which is very simple to use: fastify-http-proxy. The problem is I don't know how to use this package within Nestjs.

Does anybody here any experience with this, please?

import { NestFactory } from '@nestjs/core';
import {
  FastifyAdapter,
  NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
import proxy from 'fastify-http-proxy';

async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter({logger: true})
  );
  app.register(proxy, {
      upstream: 'http://localhost:3000',
      prefix: '/api',
      http2: false
    });

  await app.listen(4000);
}
bootstrap();

$ npm run start

> [email protected] start /test-api-gateway
> nest start

node_modules/fastify-http-proxy/index.d.ts:18:29 - error TS2344: Type 'RawServerBase' does not satisfy the constraint 'RouteGenericInterface'.
  Type 'Server' has no properties in common with type 'RouteGenericInterface'.

18     request: FastifyRequest<RawServerBase>,
                               ~~~~~~~~~~~~~
node_modules/fastify-http-proxy/index.d.ts:23:29 - error TS2344: Type 'RawServerBase' does not satisfy the constraint 'RouteGenericInterface'.
  Type 'Server' has no properties in common with type 'RouteGenericInterface'.

23     request: FastifyRequest<RawServerBase>,
                               ~~~~~~~~~~~~~

Found 2 error(s).

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `nest start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
✘-1 ~/test-api-gateway 
 

Upvotes: 0

Views: 1495

Answers (1)

User2847529116
User2847529116

Reputation: 1

it works for me if using const proxy = require('fastify-http-proxy') instead import proxy from 'fastify-http-proxy'

Upvotes: 0

Related Questions