http only cookie 不适用于带有反向代理的 express js

http only cookie not working on express js with reverse proxy

大家好,我有一个节点 js 应用程序,我使用 nginx 作为反向代理。 每当我设置 cookie 时它都有效,但没有勾选 httpOnly 和安全标志, 请问我需要解决方案这是问题的图片the cookie when set on browser

my nginx configuration

app.set("trust proxy", 1);
app.use(helmet());
app.use(
  cors({
    credentials: true,
    origin: [
      "http://localhost:8080",
      "http://thegainer.xyz",
      "https://thegainer.xyz"
    ],
    exposedHeaders: ["set-cookie"]
  })
); 



  res.cookie("token", JSON.stringify(accessToken), {
secure: true,
httpOnly: true,
maxAge: 2592000000

});

哦,抱歉,我得到了答案。

忘记在我的前端代码中添加 app.set("trust proxy",1) 这是因为我没有将 nginx 用于静态文件而是另一个 nodejs 服务器