需求
前端 需要连接后台地址,每次换别人联调都要修改,好几个项目的时候,就要改好几个
关键每次git提交 还会显示文件修改了
强迫症患者 表示 忍不了
群里有人给了个脚本 有时间可以替换nginx
https://github.com/fastify/fastify-http-proxy/blob/HEAD/examples/example.js
研究暂时失败
改nginx先用着
location /aizzb-api {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'POST,GET,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Authorization'; #跨域设置
proxy_pass http://192.168.40.169:59090/aizzb-api/; # 广湖
#proxy_pass http://192.168.41.92:59090/aizzb-api/; # 秀洋
}
用nestjs做网关 代理转发api接口
$ npm i -g @nestjs/cli
$ nest new tf-gateway-http-proxy
$ npm install @nestjs/platform-fastify --save
import { NestFactory } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
);
await app.listen(3000);
}
bootstrap();
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({
logger: false
}),
);
// fastify通过app.register的方式注册插件
app.register(require('@fastify/http-proxy'), {
upstream: otherUrl,
prefix: '/proxy' //本地的路由
});
//其他设置
}
资料
nestjs做接口转发
https://www.cnblogs.com/Mr-Kahn/p/16334204.html