使用satellizer登录facebook并使用nodejs ... 它在localhost中工作,但不在heroku app中工作
如何使用heroku app解决此问题,超时问题
错误响应:config:Object {方法:" POST",withCredentials:false,url:" / auth / twitter",...} 数据:" \ n \ t \ n \ t \ n \ t \ t \ n \ t \ t \ n \ t \ t \ t应用程序错误\ n \ t \ t \ n \ t \ t \ thtml,body,iframe {\ n \ t \ t \ t \ tmargin:0; \ n \ t \ t \ tpadding:0; \ n \ t \ t} \ n \ t \ t html,body {\ n \ t \ t \ theight:100 %; \ n \ t \ t \ toverflow:hidden; \ n \ t \ t} \ n \ t \ t iframe {\ n \ t \ t \ twidth:100%; \ n \ t \ t \ theight:100 %; \ n \ t \ t \ tborder:0; \ n \ t \ t}:\ n \ t \ t \ n \ t \ n \ t \ n \ t \ n \ t \ n \ t \ n \ t&#34 ; headers:function headersGetter /<() 状态:503 statusText:"服务不可用"
/*
|--------------------------------------------------------------------------
| Login with Facebook
|--------------------------------------------------------------------------
*/
app.post('/auth/facebook', function(req, res) {
var fields = ['id', 'email', 'first_name', 'last_name', 'link', 'name'];
var accessTokenUrl = 'https://graph.facebook.com/v2.5/oauth/access_token';
var graphApiUrl = 'https://graph.facebook.com/v2.5/me?fields=' + fields.join(',');
var params = {
code: req.body.code,
client_id: req.body.clientId,
client_secret: config.FACEBOOK_SECRET,
redirect_uri: req.body.redirectUri
};
// Step 1. Exchange authorization code for access token.
request.get({ url: accessTokenUrl, qs: params, json: true }, function(err, response, accessToken) {
if (response.statusCode !== 200) {
return res.status(500).send({ message: accessToken.error.message });
}
// Step 2. Retrieve profile information about the current user.
request.get({ url: graphApiUrl, qs: accessToken, json: true }, function(err, response, profile) {
if (response.statusCode !== 200) {
return res.status(500).send({ message: profile.error.message });
}
if (req.header('Authorization')) {
User.findOne({ facebook: profile.id }, function(err, existingUser) {
if (existingUser) {
return res.status(409).send({ message: 'There is already a Facebook account that belongs to you' });
}
var token = req.header('Authorization').split(' ')[1];
var payload = jwt.decode(token, config.TOKEN_SECRET);
User.findById(payload.sub, function(err, user) {
if (!user) {
return res.status(400).send({ message: 'User not found' });
}
user.facebook = profile.id;
user.picture = user.picture || 'https://graph.facebook.com/v2.3/' + profile.id + '/picture?type=large';
user.displayName = user.displayName || profile.name;
user.save(function() {
var token = createJWT(user);
res.send({ token: token });
});
});
});
} else {
// Step 3. Create a new user account or return an existing one.
User.findOne({ facebook: profile.id }, function(err, existingUser) {
if (existingUser) {
var token = createJWT(existingUser);
return res.send({ token: token });
}
var user = new User();
user.facebook = profile.id;
user.picture = 'https://graph.facebook.com/' + profile.id + '/picture?type=large';
user.displayName = profile.name;
user.save(function() {
var token = createJWT(user);
res.send({ token: token });
});
});
}
});
});
});