Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Express 为什么我的heroku日志显示相同请求的无限重复?_Express_Heroku_Graphql_Next.js_Http Proxy - Fatal编程技术网

Express 为什么我的heroku日志显示相同请求的无限重复?

Express 为什么我的heroku日志显示相同请求的无限重复?,express,heroku,graphql,next.js,http-proxy,Express,Heroku,Graphql,Next.js,Http Proxy,第一次在StackOverflow上发帖是在快乐地读了很多年之后,如果写得不正确,我深表歉意。 我们最近推出了React/NextJS应用程序,由Heroku主持。我们有一个单独的GraphQL瑜伽服务器来处理和发送正确的数据,该服务器也是由Heroku托管的。您可以访问位于的应用程序。我的数据库(Prisma)向我们的数据库报告了100000个请求,尽管我是唯一使用该网站的人。我查看了Heroku的日志,发现了一个非常奇怪的模式。首先,GET请求: 2020-05-27T13:40:18.88

第一次在StackOverflow上发帖是在快乐地读了很多年之后,如果写得不正确,我深表歉意。 我们最近推出了React/NextJS应用程序,由Heroku主持。我们有一个单独的GraphQL瑜伽服务器来处理和发送正确的数据,该服务器也是由Heroku托管的。您可以访问位于的应用程序。我的数据库(Prisma)向我们的数据库报告了100000个请求,尽管我是唯一使用该网站的人。我查看了Heroku的日志,发现了一个非常奇怪的模式。首先,GET请求:

2020-05-27T13:40:18.883461+00:00 heroku[router]: at=info method=GET path="/" host=www.sayplants.com request_id=36c364a0-012b-4927-813d-314bd3674657 fwd="176.249.98.203" dyno=web.1 connect=1ms service=150ms status=200 bytes=4252 protocol=https
然后,一个具有相同请求id的POST请求,但在“fwd”字段中添加了一个代理:

然后,POST请求一次又一次地重复,每次都将(相同的)代理添加到“fwd”(Heroku的X-Forwarded-for缩写),因此我们有
fwd=“176.249.98.203,54.216.239.50”
,在下一个日志中我们有
fwd=“176.249.98.203,54.216.239.50,54.216.239.50”
,然后是
fwd=“176.249.98.203、54.216.239.50、54.216.239.50、54.216.239.50”
,依此类推,直到有数百个相同的IP地址反复出现

经过仔细检查,我们能够通过从NextJS应用程序中删除我们的用户信息请求来删除生产中的这种行为-删除以下内容:

const User = props => (
  <Query {...props} query={CURRENT_USER_QUERY}>
    {payload => props.children(payload)}
  </Query>
);

User.propTypes = {
  children: PropTypes.func.isRequired,
};

export default User;
但显然我们需要用户功能!所以我们已经隔离了这个问题,但不知道如何解决它

如果您仍然与我在一起,为了完整起见,这是我们的后端查询解析器:

    async me(parent, args, ctx, info) {
        if(!ctx.request.userId) {
            return null;
        }
        const user = await ctx.db.query.user({
            where: { id: ctx.request.userId }
        }, info);
        return user
    },
其中request.userId由某个Express中间件设置

server.express.use(cookieParser());

server.express.use((req, res, next) => {
  const { token } = req.cookies;
  if (token) {
    const { userId } = jwt.verify(token, process.env.APP_SECRET)
    req.userId = userId
  }
  next();
});
任何帮助都将不胜感激。在这件事上我的头撞了好几天

    async me(parent, args, ctx, info) {
        if(!ctx.request.userId) {
            return null;
        }
        const user = await ctx.db.query.user({
            where: { id: ctx.request.userId }
        }, info);
        return user
    },
server.express.use(cookieParser());

server.express.use((req, res, next) => {
  const { token } = req.cookies;
  if (token) {
    const { userId } = jwt.verify(token, process.env.APP_SECRET)
    req.userId = userId
  }
  next();
});