在Next js中更改axios post请求中的origin名称

问题描述 投票:0回答:1

我想更改 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)

给我正确的答案来解决这个问题,我非常感激。

我期待这种类型的回应,

next.js axios request next
1个回答
0
投票

检查您已给出基本 url 的 env 文件。根据使用的环境,基本地址会发生变化。

© www.soinside.com 2019 - 2024. All rights reserved.