проблема с nest js + fastify-http-proxy - PullRequest
0 голосов
/ 01 августа 2020

Я пытаюсь создать прокси-сервер Nest js api (сквозной). Я нашел этот очень простой в использовании пакет: fastify-http-proxy. Проблема в том, что я не знаю, как использовать этот пакет в Nest js.

Есть ли у кого-нибудь здесь опыт работы с этим, пожалуйста?

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

> test-api-gateway@0.0.1 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! test-api-gateway@0.0.1 start: `nest start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the test-api-gateway@0.0.1 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 
 
...