我想更改 axios 请求标头中的源名称,如
bookshop.webmanza.com
。我这样传递我的代码,
const customOrigin = "bookshop.webmanza.com";
export const http = Axios.create({
// eslint-disable-next-line no-undef
baseURL: process.env.NEXT_PUBLIC_API_URL,
headers: {
"Access-Control-Allow-Origin": "*",
Origin: customOrigin,
},
});
但不幸的是,它总是重定向到
http://localhost:3000
,但有趣的是,当我在请求标头中传递 origin 时,邮递员已被称为此 api。它不会覆盖。供您参考,我正在使用 next js 13 并且 API 已在根级别组件中调用,如 Layout.tsx
文件,我的操作系统是 linux(ubuntu 20.4)
给我正确的答案来解决这个问题,我非常感激。
检查您已给出基本 url 的 env 文件。根据使用的环境,基本地址会发生变化。