简体   繁体   English

外部Web服务将用户重定向并将数据发布到我的回调URL。 如何在Express / Next.js应用程序中将发布的数据呈现给用户?

[英]External web service redirects the user and posts data to my callback URL. How do I render the posted data to the user in an Express/Next.js app?

Any help would be hugely appreciated! 任何帮助将不胜感激! Been stuck on this for a few days. 坚持了几天。

I have an Express/Next.js app where: 我有一个Express / Next.js应用程序,其中:

  • I send the user to an external website 我将用户发送到外部网站
  • user makes a payment 用户付款
  • external website redirects and posts data back to my callback URL. 外部网站重定向并将数据发布回我的回调URL。

So now I have the user on a mysite.com/payment-complete route but also want to display the data that was sent back. 因此,现在我使用户处于mysite.com/payment-complete路径上,但也想显示发送回的数据。

I have an app.post endpoint to successfully grab the data: 我有一个app.post端点可以成功获取数据:

app.post("/payment-complete", async (req, res) => {
  const transactionID = req.body.trans_id;
});

How would I pass the data to the user who is already on that route? 如何将数据传递给已经在该路由上的用户? Or pass the data before the page is rendered? 还是在呈现页面之前传递数据?

The flow of data is third party > my server > user and I'm not sure how to make this work. 数据流是第三方>我的服务器>用户,我不确定如何使它工作。

I'd be grateful for any help/direction with this. 如果有任何帮助/指导,我将不胜感激。

If anyone comes across this - the problem was that in Express (and other languages) you can't redirect or render a view for an AJAX POST request but you can if the POST request is coming from a submitted html form. 如果有人遇到这-问题是,在快车(和其他语言),你不能重定向或渲染一个AJAX POST请求的视图,但你可以 ,如果POST请求是从提交的HTML表单来的。 The web service was in fact POST-ing the data and redirecting my users with a form and so I could render a view. 实际上,Web服务正在发布数据,并使用表单重定向用户,因此我可以呈现视图。

Following code worked using Handlebars templating engine to send the render. 以下代码使用Handlebars模板引擎发送渲染。

router.post("/payment-ok", async (req, res) => {
  const transactionID = req.body.trans_id;
  return res.render("rendertest", { id: transactionID });
});

Should also possibly work with app.render to send a Next.js view instead, but I wanted to render from a separate routes file. 应该也可以与app.render一起发送Next.js视图,但是我想从单独的路由文件中进行渲染。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让我的 Next.js 应用在运行 ubuntu-latest 的 Azure 应用服务中启动? - How do I get my Next.js app to start in an Azure App Service running ubuntu-latest? 在 express 中,如何将用户重定向到外部 url? - In express how do I redirect a user to an external url? 如何在React Universal中呈现从REST服务接收的数据? (Next.js) - How to render data received from a REST service in React Universal? (Next.js) 如何检查用户是否在 Next.js 中的每个请求中登录? - How do I check if a user is logged in on every request in Next.js? 如果写入 web 的 URL 我可以从 API 访问数据,但是当我在 getServerSideProps 中获取时它无法在 Next.js (nextAuth) 中获取 session - If write the URL of the web I can access the data from API, but when If I fetch in getServerSideProps it cannot get the session in Next.js (nextAuth) 我必须在 Next.js 项目中使用 express 吗? - Do I have to use express in Next.js project? 如何将 Next.js 正确配置为前端,将 Express 应用程序配置为后端? - How to properly configure Next.js as a frontend and Express app as a backend? 如何反序列化发布到我的NodeJS / Express Web应用程序的数组/对象? - How can I deserialize arrays/objects posted to my NodeJS/Express web app? 如何在 next.js 中使用 supertest 测试 express 服务器? - How can I test express server with supertest in next.js? Express JS Web应用程序上的用户登录和身份验证 - User login and authentication on a Express JS web app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM