如何从后端(nodejs)重定向到前端(反应)?
How to redirect from backend (nodejs) to frontend (react)?
我想在域名为 source.com
的网站上添加提交表单,当用户提交按钮时,我想将他重定向到域名为 target.com
的网站。在 target.com
托管的应用程序在 backend.target.com
有一个后端,在 frontend.target.com
有一个前端。
在 source.com
我有:
<form action="https://backend.target.com" method="POST">
<input type="text" id="textId" name="textName">
<input type="submit" value="Submit">
</form>
我的问题是,我想在后端收到 post 请求后以某种方式重定向前端的用户。我怎样才能做到这一点?
我认为最好有这样的服务。通过 REST 服务 (Look here) 提交表单,等待响应,并根据该响应决定导航客户端的位置。
你的客户可以是这样的
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title: 'React POST Request Example' })
};
fetch('http://someapi', requestOptions)
.then(response => //redirect to whereever)
我想在域名为 source.com
的网站上添加提交表单,当用户提交按钮时,我想将他重定向到域名为 target.com
的网站。在 target.com
托管的应用程序在 backend.target.com
有一个后端,在 frontend.target.com
有一个前端。
在 source.com
我有:
<form action="https://backend.target.com" method="POST">
<input type="text" id="textId" name="textName">
<input type="submit" value="Submit">
</form>
我的问题是,我想在后端收到 post 请求后以某种方式重定向前端的用户。我怎样才能做到这一点?
我认为最好有这样的服务。通过 REST 服务 (Look here) 提交表单,等待响应,并根据该响应决定导航客户端的位置。
你的客户可以是这样的
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title: 'React POST Request Example' })
};
fetch('http://someapi', requestOptions)
.then(response => //redirect to whereever)