如何在同一个project Node.js中的另一个GAE服务上列出一个GAE服务的白名单

如何在同一个project Node.js中的另一个GAE服务上列出一个GAE服务的白名单,node.js,google-app-engine,ip,whitelist,local-network,Node.js,Google App Engine,Ip,Whitelist,Local Network,我有两台服务器。第一个是使用Apollo Server的后端,另一个是使用Next.js的前端服务器 后端托管在api.example.com,前端托管在。这两个服务器都作为同一个应用程序中的两个不同服务在Google App Engine上运行 我遇到的问题是,我使用graphql查询复杂性对我的应用程序应用了速率限制,而且它也对我的前端服务器进行了速率限制,因为前端服务器使用服务器端呈现来预加载请求数据 我的问题是:如何将我的前端服务器列为白名单,以便它可以根据需要发出尽可能多的请求,而不必

我有两台服务器。第一个是使用Apollo Server的后端,另一个是使用Next.js的前端服务器

后端托管在api.example.com,前端托管在。这两个服务器都作为同一个应用程序中的两个不同服务在Google App Engine上运行

我遇到的问题是,我使用graphql查询复杂性对我的应用程序应用了速率限制,而且它也对我的前端服务器进行了速率限制,因为前端服务器使用服务器端呈现来预加载请求数据

我的问题是:如何将我的前端服务器列为白名单,以便它可以根据需要发出尽可能多的请求,而不必在每次我将新代码推送到前端服务器上的生产环境时手动使用服务器IP地址更新环境变量?我也不确定我对后端的前端请求是使用本地网络还是使用www

以下是与限制我的服务器速率相关的代码:

if (config.NODE_ENV !== 'test') {
        // If the cost of the query is more than 500 throw an error
        if (cost > 500) {
          throw new Error(`Query cost exceeds single request token limit. The limit is 500 tokens and the query has a cost of ${cost} tokens. Please reduce the query cost and try again.`);
        }

        // Ensure that the IP Address is present on the request
        if (context && context.req && context.req.connection && context.req.connection.remoteAddress && context.req.connection.remoteAddress !== ---- not sure what to do about this ----) {
          // Check if there is a token allotment already in the database for that IP Address
          const tokens = await redis.get(context.req.connection.remoteAddress);

          console.log(tokens, cost);

          if (tokens !== null) {
            // If the request would exceed the token allotment
            if (tokens - cost < 0) {
              throw new Error('This request would exceed your token allotment. Please reduce the query cost or wait one minute and try again.');
            }
            // Decrement the token allotmetment by the cost of the query
            await redis.decrby(context.req.connection.remoteAddress, cost);
          } else {
            // Set the value and time-to-live of the token allotment
            await redis.setex(context.req.connection.remoteAddress, 60, 5000 - cost);
          }
        } else {
          throw new Error('An error occured within the request cost calculator. Please try again.');
        }
      }
if(config.NODE_ENV!=“测试”){
//如果查询的开销超过500,则抛出一个错误
如果(成本>500){
抛出新错误(`查询开销超过了单个请求令牌限制。限制为500个令牌,查询的开销为${cost}个令牌。请降低查询开销,然后重试。`);
}
//确保请求中存在IP地址
if(context&&context.req&&context.req.connection&&context.req.connection.remoteAddress&&context.req.connection.remoteAddress!==----不确定该怎么办--){
//检查数据库中是否已经为该IP地址分配了令牌
const tokens=wait redis.get(context.req.connection.remoteAddress);
console.log(令牌、成本);
如果(令牌!==null){
//如果请求将超过令牌分配
if(代币-成本<0){
抛出新错误('此请求将超过您的令牌分配。请降低查询成本或等待一分钟,然后重试');
}
//按查询成本递减令牌分配
等待redis.decrby(context.req.connection.remoteAddress,cost);
}否则{
//设置令牌分配的值和生存时间
wait redis.setex(context.req.connection.remoteAddress,605000-成本);
}
}否则{
抛出新错误('请求成本计算器中发生错误。请重试');
}
}

您可以检查标题
X-Appengine-Inbound-Appid
。当您在服务/项目之间发出http请求时,App engine会自动添加它(注意:您必须将请求发送到该服务的appspot.com url)


您可以检查标题
X-Appengine-Inbound-Appid
。当您在服务/项目之间发出http请求时,App engine会自动添加它(注意:您必须将请求发送到该服务的appspot.com url)