이전글 ( http://spectrumdig.blogspot.kr/2013/10/spiderable-package.html )에서 meteor가 어떻게 봇들에게 렌더링된 이후의 html을 전달하는지 보았다. 근데 만일 node.js에서 같은 구현을 해야한다면? 역시 request를 까발려서 _escaped_fragment_ 가 있는지 user-agent가 어떤 것인지 분별하면 된다. 방법이야 여러가지가 있을 텐데 preprocessor를 사용하여 가로채서 조건에 맞으면 처리하고 아닐 경우 next()로 포워딩하는 방법이 있고 ( https://github.com/acidsound/pushpot/blob/master/app.js#L30 ) Express/Connect Middle-ware를 사용하여 app.use(function(req, res, next){ if (req.query._escaped_fragment_ || [/^facebookexternalhit/i, /^linkedinbot/i, /^twitterbot/i].some(function(v) { return v.test(req.headers['user-agent']); })) { // render by phantomJS res.send(getHTMLfromPhantomJS(req.url)); } else { next(); } 이런 식으로 처리해주면 되겠다.발로 짜서 실제 작동 여부는 모르겠다. getHTMLfromPhantomJS 는 물론 직접 구현하시라 :p https://github.com/meteor/meteor/blob/devel/packages/spiderable/spiderable.js 이런식으로 구현하면 됨.
Meteor evangelist, IoT, Renoise, Lua, Javascript, Coffeescript