标准res.redirect('/some/path');
按预期运行并立即将请求重定向到/some/path
,但如果我添加状态代码,例如,res.redirect(401, '/some/path')
我导航到重定向页面,express
则不会重定向到/some/path
,而是我只是得到以下页面:
<p>Unauthorized. Redirecting to <a href="/some/path">/</a></p>
Run Code Online (Sandbox Code Playgroud)
它永远不会重定向.对于我提供的任何状态代码,这都是相同的.
为什么代码没有指定重定向工作,因为我期待它,如何返回自定义状态代码并重定向到不同的路径?
题:
我目前正在使用 webhook:当checkout.session.completed
接收到事件时,即使我尝试使用 res.redirect("/page") (Node.js) 将用户重定向到另一个页面,默认情况下也会将用户重定向到 success_url。如果我的执行代码失败,真的没有办法将他重定向到另一个页面吗?(即:支付成功,但是履行码失败,所以重定向到success_url是不合适的)
参考:
https://stripe.com/docs/payments/checkout/one-time
https://stripe.com/docs/payments/checkout/fulfillment#webhooks
“在您的客户被重定向之前,checkout.session.completed webhook 会发送到您的服务器。您的 webhook 确认(任何 2xx 状态代码)将触发客户重定向到 success_url”
我试过的:
将 Express.js 4 的 res.status(401) 链接到重定向
因此,如果我要发送 4xx 状态代码,那不应该阻止 success_url 重定向吗?这确实是我观察到的。
但我似乎无法重定向到另一个页面。我试过:
res.status(401).location('/submit/wait/').end();
res.redirect(401, '/submit/wait/');
res.set('Content-Type', 'text/html');
res.status(401).send('<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=/submit/wait"></head></html>`);Is there really no way to then just redirect to another page ?
Run Code Online (Sandbox Code Playgroud)
代码
router.post('/webhook', bodyParser.raw({type: 'application/json'}), (req, res) => {
const sig = req.headers['stripe-signature'];
let event;
try {
event = stripe.webhooks.constructEvent(req.rawBody, sig, endpointSecret);
} catch (err) { …
Run Code Online (Sandbox Code Playgroud)