【问题标题】:issue with nestjs + fastify-http-proxyNestjs + fastify-http-proxy 的问题
【发布时间】:2020-11-22 05:18:51
【问题描述】:

我正在尝试构建一个 Nestjs api 代理(通过)。我发现这个包使用起来非常简单:fastify-http-proxy。 问题是我不知道如何在 Nestjs 中使用这个包。

请问这里有人有这方面的经验吗?

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 
 

【问题讨论】:

  • 你使用的是什么模块的版本?

标签: nestjs node-http-proxy fastify


【解决方案1】:

如果使用const proxy = require('fastify-http-proxy') 而不是import proxy from 'fastify-http-proxy',它对我有用

【讨论】:

    猜你喜欢
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    • 2021-02-12
    • 1970-01-01
    • 2015-09-25
    • 2021-08-14
    • 2020-12-22
    相关资源
    最近更新 更多