我如何在Next.js重写传递体参数?



我有这个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",
}
]
: [];
},
}

我如何指定体参数(grant_type,client_id,client_secret,usernamepassword)到这个Next.js重写?我得到的错误表明这些值在我的重写中不存在:

fail: IdentityServer4.Validation.ClientSecretValidator[0]
No client identifier found

我不知道Next.js,但是您是否尝试将url添加到客户端配置为允许的Cors起源?

您可以在开发客户端中添加urlhttp://localhost:3000