@gapi/ 伪造
下载二进制
wget https://github.com/Stradivario/gapi/raw/master/packages/federation/bin/federation-linux
允许它执行
chmod +x federation-linux
开始吧
./federation-linux
如果你喜欢 javascript 您可以下载 js 二进制但需要 Nodejs 将安装在系统中
wget https://github.com/Stradivario/gapi/raw/master/packages/federation/bin/federation-linux.js
配置
默认配置文件是 gateway.config.json
{
"port": 4000,
"serviceList": [
{
"name": "projects",
"url": "http://localhost:9000/graphql"
}
]
}
您可以指定自定义配置名称
./federation-linux ./gateway.config.json
另一种通过选项的配置是环境变量
export GATEWAY_PORT=4000
export GATEWAY_SERVICE_LIST='[{"name":"projects", "url":"http://localhost:9000/graphql"}]'
您可以使用 npm 并进一步扩大范围
npm install @gapi/federation @rxdi/core
import { FederationModule } from '@gapi/federation';
import { Bootstrap } from '@rxdi/core';
Bootstrap(
FederationModule.forRoot({
port: 4000,
willSendRequest({ request, context }) {
request.http.headers.set('authorization', context.headers.authorization);
},
serviceList: [
{ name: 'accounts', url: 'http://localhost:9000/graphql' },
{ name: 'products', url: 'http://localhost:9001/graphql' },
],
apolloServerConfig: {
playground: true,
},
}),
).subscribe(() => console.log('started'));
夹克
FROM node
WORKDIR /home
RUN wget https://github.com/Stradivario/gapi/raw/master/packages/federation/bin/federation-linux.js
ARG GATEWAY_PORT
ARG GATEWAY_SERVICE_LIST
ENV GATEWAY_PORT=$GATEWAY_PORT
ENV GATEWAY_SERVICE_LIST=$GATEWAY_SERVICE_LIST
RUN ls -lha
COPY api-started.sh .
RUN chmod +x api-started.sh
EXPOSE $GATEWAY_PORT
CMD ["node", "federation-linux.js"]