res.redirect 不重定向 Node/Express.js
res.redirect doesn't redirect Node/Express.js
我正在为我的网络应用程序使用 Express,我正在检查会话中是否不存在某些值,将用户重定向到 instagram 登录页面。但是在控制台中,我不断收到 302 代码,并且浏览器不会在此处重定向用户,这是我的代码。我正在使用 Ajax.
发送我的请求
function requireLogin (req, res, next) {
if (!req.token)
res.redirect('/auth');
else
next();
};
app.get('/auth',function(req,res,next){
res.redirect("https://api.instagram.com/oauth/authorize/?client_id="+client_id+"&redirect_uri="+redirect_uri+"&score=public_content+likes+comments+follower_list+relationships&response_type=code");
});
我检查过 app.get('/auth') 被调用,但似乎第二次重定向到 instagram 没有做任何事情。
问题是如果您使用 Ajax,res.redirect 不会重定向用户。所以我将 url 传递给客户端并使用 window.location.replace(url);
您在使用 Ajax 吗?如果是,你不能直接重定向,而是发回URL,前端会重定向到你服务器发送的URL
我正在为我的网络应用程序使用 Express,我正在检查会话中是否不存在某些值,将用户重定向到 instagram 登录页面。但是在控制台中,我不断收到 302 代码,并且浏览器不会在此处重定向用户,这是我的代码。我正在使用 Ajax.
发送我的请求 function requireLogin (req, res, next) {
if (!req.token)
res.redirect('/auth');
else
next();
};
app.get('/auth',function(req,res,next){
res.redirect("https://api.instagram.com/oauth/authorize/?client_id="+client_id+"&redirect_uri="+redirect_uri+"&score=public_content+likes+comments+follower_list+relationships&response_type=code");
});
我检查过 app.get('/auth') 被调用,但似乎第二次重定向到 instagram 没有做任何事情。
问题是如果您使用 Ajax,res.redirect 不会重定向用户。所以我将 url 传递给客户端并使用 window.location.replace(url);
您在使用 Ajax 吗?如果是,你不能直接重定向,而是发回URL,前端会重定向到你服务器发送的URL