正如标题中所述,在使用 ngrok 进行隧道传输时,我很难设置用于身份验证目的的 http cookie。
\n当我在开发环境中运行从 localhost 到 localhost 端点的查询时,以下代码工作正常(显然指定了相关端点),但一旦我开始查询 ngrok 隧道端点,它就会崩溃。
\n前端 api 查询(简化为大型应用程序的一部分)
\nfunction 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)