我在 heroku 上的 twitter 护照有问题,同时它在 localhost 上运行良好。我无法在 heroku 上登录,并且 web 应用程序在回调期间超时。回调期间似乎发生了一些错误。这是网站:
https://nightlife-app-klm.herokuapp.com
路线 > index.js
app.route('/login')
.get(function (req, res) {
res.redirect('/auth/twitter');
});
app.route('/auth/twitter')
.get(passport.authenticate('twitter'));
app.route('/auth/twitter/callback')
.get(passport.authenticate('twitter', {
successRedirect: '/',
failureRedirect: '/'
}));
服务器.js
require('./js/config/passport')(passport);
app.use(session({
secret: 'secret',
resave: false,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
routes(app, passport);
配置 > 护照
var TwitterStrategy = require('passport-twitter').Strategy;
var User = require('../models/users');
var configAuth = require('./auth');
module.exports = function (passport) {
passport.serializeUser(function (user, done) {
done(null, user.id);
});
passport.deserializeUser(function (id, done) {
User.findById(id, function (err, user) {
done(err, user);
});
});
passport.use(new TwitterStrategy({
consumerKey: configAuth.twitterAuth.clientID,
consumerSecret: configAuth.twitterAuth.clientSecret,
callbackURL: configAuth.twitterAuth.callbackURL
},
function (token, refreshToken, profile, done) {
process.nextTick(function () {
User.findOne({ 'twitter.id': profile.id }, function (err, user) {
if (err) return done(err);
if (user) return done(null, user);
else {
var newUser = new User();
newUser.twitter.id = profile.id;
newUser.twitter.username = profile.username;
newUser.twitter.displayName = profile.displayName;
newUser.save(function (err) {
if (err) throw err;
return done(null, newUser);
});
}
});
});
}));
};
这是heroku的构建成功日志:
2017-06-17T22:12:07.000000+00:00 app[api]: Build succeeded
2017-06-17T22:12:29.117559+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2017-06-17T22:12:29.288019+00:00 heroku[web.1]: Process exited with status 143
2017-06-17T22:12:31.790469+00:00 heroku[web.1]: Starting process with command `node bin/dev.js`
2017-06-17T22:12:36.883046+00:00 heroku[web.1]: State changed from starting to up
2017-06-17T22:12:36.799768+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2017-06-17T22:12:36.799779+00:00 app[web.1]: designed for a production environment, as it will leak
2017-06-17T22:12:36.799780+00:00 app[web.1]: memory, and will not scale past a single process.
2017-06-17T22:12:36.844434+00:00 app[web.1]: Node.js listening on port 13639...
这是我运行它然后刷新时的日志:
2017-06-17T22:17:20.185119+00:00 heroku[router]: at=info method=GET path="/" host=nightlife-app-klm.herokuapp.com request_id=ebde13cc-6b63-4ea7-b72e-61d701414d88 fwd="24.254.137.110" dyno=web.1 connect=1ms service=105ms status=304 bytes=275 protocol=https
2017-06-17T22:17:20.220548+00:00 heroku[router]: at=info method=GET path="/src/js/bundle.min.js" host=nightlife-app-klm.herokuapp.com request_id=cfa93ef2-d48c-4f1a-91b8-ab3d9a95c370 fwd="24.254.137.110" dyno=web.1 connect=1ms service=10ms status=304 bytes=240 protocol=https
2017-06-17T22:17:20.479606+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=nightlife-app-klm.herokuapp.com request_id=c0f69015-7700-47c0-9bcf-0d525dcd5beb fwd="24.254.137.110" dyno=web.1 connect=1ms service=8ms status=304 bytes=151 protocol=https
2017-06-17T22:17:29.246249+00:00 heroku[router]: at=info method=GET path="/login" host=nightlife-app-klm.herokuapp.com request_id=08aec5bc-22c1-4fa3-9b09-d379f5d14773 fwd="24.254.137.110" dyno=web.1 connect=1ms service=70ms status=302 bytes=270 protocol=https
2017-06-17T22:17:29.548055+00:00 heroku[router]: at=info method=GET path="/auth/twitter" host=nightlife-app-klm.herokuapp.com request_id=9d75bb12-5b9e-40ee-9866-932c5281acb0 fwd="24.254.137.110" dyno=web.1 connect=1ms service=279ms status=302 bytes=214 protocol=https
2017-06-17T22:18:00.469532+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/auth/twitter/callback?oauth_token=QCKSqwAAAAAA1FpSAAABXLgh6jo&oauth_verifier=lKvM9GC3ADf501BZU9DG8vZyo2myai5T" host=nightlife-app-klm.herokuapp.com request_id=3e81f6e1-7217-4ead-92d3-bf9adbcb953c fwd="24.254.137.110" dyno=web.1 connect=2ms service=30001ms status=503 bytes=0 protocol=https
2017-06-17T22:18:00.829430+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=nightlife-app-klm.herokuapp.com request_id=7152807a-ba07-48c9-a0fe-c5e6b3f18341 fwd="24.254.137.110" dyno=web.1 connect=1ms service=9ms status=304 bytes=151 protocol=https
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2017-06-17T22:12:36.799768+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2017-06-17T22:12:36.799779+00:00 app[web.1]: designed for a production environment, as it will leak
2017-06-17T22:12:36.799780+00:00 app[web.1]: memory, and will not scale past a single process.
2017-06-17T22:12:36.844434+00:00 app[web.1]: Node.js listening on port 13639...
2017-06-17T22:17:20.185119+00:00 heroku[router]: at=info method=GET path="/" host=nightlife-app-klm.herokuapp.com request_id=ebde13cc-6b63-4ea7-b72e-61d701414d88 fwd="24.254.137.110" dyno=web.1 connect=1ms service=105ms status=304 bytes=275 protocol=https
2017-06-17T22:17:20.220548+00:00 heroku[router]: at=info method=GET path="/src/js/bundle.min.js" host=nightlife-app-klm.herokuapp.com request_id=cfa93ef2-d48c-4f1a-91b8-ab3d9a95c370 fwd="24.254.137.110" dyno=web.1 connect=1ms service=10ms status=304 bytes=240 protocol=https
2017-06-17T22:17:20.479606+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=nightlife-app-klm.herokuapp.com request_id=c0f69015-7700-47c0-9bcf-0d525dcd5beb fwd="24.254.137.110" dyno=web.1 connect=1ms service=8ms status=304 bytes=151 protocol=https
2017-06-17T22:17:29.246249+00:00 heroku[router]: at=info method=GET path="/login" host=nightlife-app-klm.herokuapp.com request_id=08aec5bc-22c1-4fa3-9b09-d379f5d14773 fwd="24.254.137.110" dyno=web.1 connect=1ms service=70ms status=302 bytes=270 protocol=https
2017-06-17T22:17:29.548055+00:00 heroku[router]: at=info method=GET path="/auth/twitter" host=nightlife-app-klm.herokuapp.com request_id=9d75bb12-5b9e-40ee-9866-932c5281acb0 fwd="24.254.137.110" dyno=web.1 connect=1ms service=279ms status=302 bytes=214 protocol=https
2017-06-17T22:18:00.469532+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/auth/twitter/callback?oauth_token=QCKSqwAAAAAA1FpSAAABXLgh6jo&oauth_verifier=lKvM9GC3ADf501BZU9DG8vZyo2myai5T" host=nightlife-app-klm.herokuapp.com request_id=3e81f6e1-7217-4ead-92d3-bf9adbcb953c fwd="24.254.137.110" dyno=web.1 connect=2ms service=30001ms status=503 bytes=0 protocol=https
2017-06-17T22:18:00.829430+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=nightlife-app-klm.herokuapp.com request_id=7152807a-ba07-48c9-a0fe-c5e6b3f18341 fwd="24.254.137.110" dyno=web.1 connect=1ms service=9ms status=304 bytes=151 protocol=https
2017-06-17T22:18:36.655387+00:00 heroku[router]: at=info method=GET path="/auth/twitter/callback?oauth_token=QCKSqwAAAAAA1FpSAAABXLgh6jo&oauth_verifier=lKvM9GC3ADf501BZU9DG8vZyo2myai5T" host=nightlife-app-klm.herokuapp.com request_id=3549756f-c91e-4cc6-bb3d-bc50932227f7 fwd="24.254.137.110" dyno=web.1 connect=1ms service=440ms status=500 bytes=404 protocol=https
2017-06-17T22:18:36.651856+00:00 app[web.1]: Error: This feature is temporarily unavailable
2017-06-17T22:18:36.651877+00:00 app[web.1]: at Strategy.parseErrorResponse (/app/node_modules/passport-twitter/lib/strategy.js:206:12)
2017-06-17T22:18:36.651878+00:00 app[web.1]: at Strategy.OAuthStrategy._createOAuthError (/app/node_modules/passport-oauth1/lib/strategy.js:393:16)
2017-06-17T22:18:36.651879+00:00 app[web.1]: at /app/node_modules/passport-oauth1/lib/strategy.js:154:43
2017-06-17T22:18:36.651879+00:00 app[web.1]: at /app/node_modules/oauth/lib/oauth.js:465:22
2017-06-17T22:18:36.651880+00:00 app[web.1]: at passBackControl (/app/node_modules/oauth/lib/oauth.js:397:13)
2017-06-17T22:18:36.651881+00:00 app[web.1]: at IncomingMessage.<anonymous> (/app/node_modules/oauth/lib/oauth.js:409:9)
2017-06-17T22:18:36.651882+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-06-17T22:18:36.651882+00:00 app[web.1]: at IncomingMessage.emit (events.js:185:7)
2017-06-17T22:18:36.651883+00:00 app[web.1]: at endReadableNT (_stream_readable.js:974:12)
2017-06-17T22:18:36.651883+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-06-17T22:18:36.651884+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:104:9)
2017-06-17T22:18:36.913563+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=nightlife-app-klm.herokuapp.com request_id=48c96a39-8bdd-4002-8e57-78246fa5c3c0 fwd="24.254.137.110" dyno=web.1 connect=21ms service=7ms status=200 bytes=968 protocol=https
Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...
2017-06-17T22:18:36.651878+00:00 app[web.1]: at Strategy.OAuthStrategy._createOAuthError (/app/node_modules/passport-oauth1/lib/strategy.js:393:16)
2017-06-17T22:18:36.651879+00:00 app[web.1]: at /app/node_modules/passport-oauth1/lib/strategy.js:154:43
2017-06-17T22:18:36.651879+00:00 app[web.1]: at /app/node_modules/oauth/lib/oauth.js:465:22
2017-06-17T22:18:36.651880+00:00 app[web.1]: at passBackControl (/app/node_modules/oauth/lib/oauth.js:397:13)
2017-06-17T22:18:36.651881+00:00 app[web.1]: at IncomingMessage.<anonymous> (/app/node_modules/oauth/lib/oauth.js:409:9)
2017-06-17T22:18:36.651882+00:00 app[web.1]: at emitNone (events.js:91:20)
2017-06-17T22:18:36.651882+00:00 app[web.1]: at IncomingMessage.emit (events.js:185:7)
2017-06-17T22:18:36.651883+00:00 app[web.1]: at endReadableNT (_stream_readable.js:974:12)
2017-06-17T22:18:36.651883+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:80:11)
2017-06-17T22:18:36.651884+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:104:9)
2017-06-17T22:18:36.913563+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=nightlife-app-klm.herokuapp.com request_id=48c96a39-8bdd-4002-8e57-78246fa5c3c0 fwd="24.254.137.110" dyno=web.1 connect=21ms service=7ms status=200 bytes=968 protocol=https