小编Dav*_*idH的帖子

使用 ngrok 隧道时难以设置 Cookie(Node.js 上的 Express 服务器、React 应用程序前端)

正如标题中所述,在使用 ngrok 进行隧道传输时,我很难设置用于身份验证目的的 http cookie。

\n

当我在开发环境中运行从 localhost 到 localhost 端点的查询时,以下代码工作正常(显然指定了相关端点),但一旦我开始查询 ngrok 隧道端点,它就会崩溃。

\n

前端 api 查询(简化为大型应用程序的一部分)

\n
function fetchRequest (path, options) {\n  const endpoint = 'http://xxx.ngrok.io'; // the ngrok tunnel endpoint\n  return fetch(endpoint + path, options)\n    .then(res => {\n      return res.json();\n    })\n    .catch((err) => {\n      console.log('Error:', err);\n    });\n}\n\nfunction postRequest (url, body, credentials='include') {\n  return fetchRequest(`${url}`, {\n    method: 'POST',\n    withCredentials: true,\n    credentials: credentials,\n    headers: {'Content-Type': 'application/json', Accept: 'application.json'},\n    body: JSON.stringify(body)\n  });\n}\n\n// data to be passed to backend for authentication\nlet data …
Run Code Online (Sandbox Code Playgroud)

cookies node.js express reactjs ngrok

6
推荐指数
0
解决办法
1220
查看次数

标签 统计

cookies ×1

express ×1

ngrok ×1

node.js ×1

reactjs ×1