[英]How can I pass body params in a Next.js rewrite?
我有这个POST
请求:
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: JSON.stringify({
grant_type: "password",
client_id: "client",
client_secret: "clientsecret",
username: "matias@gmail.com",
password: "12341234"
})
};
const token = fetch("http://localhost:3000/connect/token", requestOptions)
.then(response => console.log(response))
.catch(error => console.log(error));
我想重写它,这样我就可以绕过开发环境中的 CORS 错误。 为此,我在next.config.js
文件中有以下代码:
const nextConfig = {
reactStrictMode: false,
async rewrites() {
return process.env.NODE_ENV === "development"
? [
{
source: "/connect/token",
destination: "http://localhost:4446/connect/token",
}
]
: [];
},
}
如何为 Next.js 重写指定正文参数( grant_type
、 client_id
、 client_secret
、 username
和password
)? 我得到的错误表明这些值在我的重写中不存在:
fail: IdentityServer4.Validation.ClientSecretValidator[0]
No client identifier found
我不了解 Next.js,但您是否尝试将 url 作为Allowed Cors Origins添加到客户端配置?
您可以在您的开发客户端中添加 url http://localhost:3000
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.