Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问如何在getServiceNodeInfo函数中获得Post返回的数据做二次加工,同时对Post传递参数,在返回到controller中 #36

Open
xietianbao80 opened this issue Sep 2, 2020 · 1 comment

Comments

@xietianbao80
Copy link

xietianbao80 commented Sep 2, 2020

import { Injectable, Body, Inject } from "@nestjs/common";
import { Loadbalanced } from "@nestcloud/loadbalance";
import { Get, ost } from "@nestcloud/feign";
// import { AXIOS_INSTANCE_PROVIDER } from "@nestcloud/http/http.constants";

@Injectable()
// enable loadbalance supports, need import @nestcloud/loadbalance module at first.
@Loadbalanced("service-test")
export class ServiceNodeClient {
  // constructor(@Inject(AXIOS_INSTANCE_PROVIDER) private readonly httpService: HttpClient) {}
  // constructor() {}

  @Post("/service-test/get-service-test-info-by-caller-test")
  async getServiceNodeInfo() {}

  @Get("http://test.com/users")
  // disable loadbalance supports.
  @Loadbalanced(false)
  getRemoteUsers() {}
}

请问如何在getServiceNodeInfo函数中获得Post返回的数据做二次加工,在返回到controller中,同时对Post传递参数

@xietianbao80 xietianbao80 changed the title 请问如何在getServiceNodeInfo函数中获得Get返回的数据做二次加工,在返回到controller中 请问如何在getServiceNodeInfo函数中获得Post返回的数据做二次加工,同时对Post传递参数,在返回到controller中 Sep 2, 2020
@miaowing
Copy link
Member

miaowing commented Sep 7, 2020

可以使用 Interceptor 对数据进行处理:

import { Injectable } from '@nestjs/common';
import { Interceptor } from '@nestcloud/http';
import { AxiosResponse } from 'axios';

@Injectable()
export class TestInterceptor implements Interceptor {
  onResponse(response: AxiosResponse): AxiosResponse {
    response.data = { message: 'hello' };
    return response;
  }
}
import { Injectable } from '@nestjs/common';
import { Loadbalanced } from '@nestcloud/loadbalance';
import { Get, Post, UseInterceptors } from '@nestcloud/http';
import { TestInterceptor } from './TestInterceptor';

@Injectable()
@Loadbalanced('service-test')
export class ServiceNodeClient {
  @Post('/service-test/get-service-test-info-by-caller-test')
  @UseInterceptors(TestInterceptor)
  async getServiceNodeInfo() {
  }

  @Get('http://test.com/users')
  @Loadbalanced(false)
  getRemoteUsers() {
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants