Permalink
Browse files

dd

  • Loading branch information...
1 parent e12a5ab commit 8a4d85cc52f8d284ddb5112a3e83340a360c0a3b System Administrator committed Jan 12, 2015
Showing with 387 additions and 4 deletions.
  1. +2 −2 .gitignore
  2. +18 −0 index.js
  3. +9 −1 node_modules/express/lib/response.js
  4. +358 −1 tools/commented.json
View
@@ -1,5 +1,4 @@
config.coffee
-.gitignore
alipay_config.js
node_modules
.DS_Store
@@ -8,4 +7,5 @@ node_modules/*
uploads
sftp-config.json
lib/uploads
-lib/card-*.png
+lib/card-*.png
+route_static
View
@@ -90,6 +90,24 @@
}
return next();
});
+ app.use(function(req, res, next) {
+ var userAgent = req.headers['user-agent'].toLowerCase();
+ if(userAgent.indexOf("bot")!=-1||userAgent.indexOf("spider")!=-1) {
+ var static_path = __dirname + "/route_static/" + req.originalUrl.replace(/\//g, "_");
+ if (fs.existsSync(static_path)) {
+ var mtime = fs.statSync(static_path).mtime;
+ if (new Date().getTime() - mtime.getTime() < 1000 * 60 * 60 * 24) {
+
+ console.log("read from cache")
+ res.send(fs.readFileSync(static_path))
+ return;
+ }
+
+ } else {
+ }
+ }
+ return next();
+ });
app.use(app.router);
rainbow.route(app, {
controllers: '/controllers/',
@@ -5,6 +5,7 @@
var http = require('http')
, path = require('path')
, connect = require('connect')
+ , fs = require("fs")
, utils = connect.utils
, sign = require('cookie-signature').sign
, normalizeType = require('./utils').normalizeType
@@ -791,7 +792,14 @@ res.render = function(view, options, fn){
// default callback to respond
fn = fn || function(err, str){
if (err) return req.next(err);
- self.send(str);
+ self.send(str);
+ var userAgent = req.headers['user-agent'].toLowerCase();
+ if(userAgent.indexOf("bot")!=-1||userAgent.indexOf("spider")!=-1){
+ var static_path = __dirname+"/../../../route_static/"+req.originalUrl.replace(/\//g,"_");
+ console.log(static_path)
+ fs.writeFileSync(static_path,str,'utf-8')
+ }
+
};
// render
Oops, something went wrong.

0 comments on commit 8a4d85c

Please sign in to comment.