我有一个支付系统使用node.js和braintree,当支付成功时,我想发送用户到后端。我的后端设置在别处。在快递中,我如何将用户重定向到外部网址?
我已经试过
res.writeHead(301,
{Location: 'http://app.example.io'}
);
res.end();
所以window.location的显然是不可用的。我不能想办法重定向用户?
我有一个支付系统使用node.js和braintree,当支付成功时,我想发送用户到后端。我的后端设置在别处。在快递中,我如何将用户重定向到外部网址?
我已经试过
res.writeHead(301,
{Location: 'http://app.example.io'}
);
res.end();
所以window.location的显然是不可用的。我不能想办法重定向用户?
你可以做res.redirect('http://app.example.io');
我有同样的问题,并得到了其加入“未来”的工作。我使用路由器,所以也许你有和我一样的问题?没有下一个,我得到关于没有渲染引擎的错误...怪异的
var express = require('express');
var router = express.Router();
var debug = require('debug')('node_blog:server');
/* GET home page. */
router.get('/', function(req, res, next) {
debug("index debug");
res.render('index.html', { title: 'Express' });
});
router.post("/", function (req, res, next) {
//var pass = req.body("password");
//var loginx = req.body("login");
//res.render('index.html', { title: 'Express' });
res.redirect("/users")
next
});
module.exports = router;
选定的答案不适用于我。它将我重定向到:locahost:8080/www.google.com
- 这是无稽之谈。
301 Moved Permanently需要包含在res.status(301)
中,如下所示。
app.get("/where", (req, res) => {
res.status(301).redirect("https://www.google.com")
})
由于您的后端在别处,您处于相同的情况。
我早些时候尝试过,但我不认为它再次尝试。 – 2015-02-05 20:33:06
它重定向到'/' – 2015-02-05 20:34:17
我刚刚在个人应用上测试过它,并且它正确重定向。问题:您使用的是哪种版本的快递? – TheIronDeveloper 2015-02-05 20:37:39