我注意到,每当我使用Facebook debugger tool或Facebook like按钮(使用Addthis设置)时,ExpressJS最终会抛出Error: Forbidden
(连续两次)。
所以我假设抓取工具发送了一个奇怪的Express请求,也许是标题中的内容,就像这个issue一样?
以下是Facebook抓取工具发送的标题:
{
host: 'runningheroes.co',
accept: '*/*',
'accept-encoding': 'deflate, gzip',
range: 'bytes=0-8999',
referer: 'http://runningheroes.co/',
'user-agent': 'facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)',
'x-forwarded-for': '173.252.100.117',
'x-forwarded-port': '80',
'x-forwarded-proto': 'http',
connection: 'keep-alive'
}
这是我的Express配置:
app.configure(function(){
app.use(express.compress());
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.set('port', process.env.PORT || 8000);
app.use(express.favicon(__dirname + '/public/img/favicon.ico'));
app.use(express.logger('dev'));
app.use(express.bodyParser({ keepExtensions: true }));
app.use(express.methodOverride());
app.use(express.cookieParser('secret'));
app.use(express.cookieSession({ secret: 'secret', cookie: { domain: '.runningheroes.co', maxAge: 1000*60*60*24, httpOnly: true } }));
app.use(app.router);
// Error handling:
app.use(function(err, req, res, next) {
if(!err) { return next(); }
// This is were the Forbidden errors are logged
logger.error('Express.error.middleware: ' + err);
res.redirect('/error');
});
});
非常感谢任何帮助。
PS:尽管存在错误,调试器仍然可以成功解析og meta标签,并且类似按钮也能正常工作。