forked from chinatjnet/htmljs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
144 lines (124 loc) · 4.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Generated by CoffeeScript 1.7.1
(function() {
var app, black, config, express, fs, http, ipblack, less, lessmiddle, log4js, logger, path, rainbow, _;
express = require("express");
http = require("http");
path = require("path");
config = require('./config.coffee');
rainbow = require('./lib/rainbow.js');
lessmiddle = require('less-middleware');
less = require('less');
fs = require('fs');
global.xss = require('xss');
xss.whiteList['iframe'] = ['src', 'width', 'height', 'allowfullscreen', 'frameborder', 'id', 'class', 'style'];
_ = require('underscore');
module.exports = app = express();
log4js = require('log4js');
log4js.configure({
appenders: [{
type: 'console'
}]
});
logger = log4js.getLogger('normal');
logger.setLevel('INFO');
black = ['webmeup', 'DNSPod', 'monitor', 'snarfware', 'majestic12', 'easou', 'yunyun', 'sougou', 'sogou', 'yunrang', 'ahrefs', "longurl", 'rogerbot'];
ipblack = ['211.144.76.89'];
app.configure(function() {
var static_jades;
app.set("port", config.run_port);
app.set("views", path.join(__dirname, 'views'));
app.set("view engine", "jade");
app.use(express.favicon());
app.use("/assets", lessmiddle({
src: __dirname + "/assets",
compress: true
}));
app.use("/resumes", express["static"](__dirname + "/resumes"));
app.use("/assets", express["static"](__dirname + "/assets"));
app.use("/uploads", express["static"](__dirname + "/uploads"));
app.use("/static", express["static"](__dirname + "/static"));
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.cookieSession({
secret: config.session_secret
}));
app.use(log4js.connectLogger(logger, {
level: log4js.levels.INFO
}));
app.use(function(req, res, next) {
var agent, i, _i, _ref;
res.locals.url = req.url;
agent = req.get("user-agent");
if (!agent) {
res.end(' hello robot 1');
return;
}
for (i = _i = 0, _ref = black.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
if (agent.indexOf(black[i]) !== -1) {
res.end(' hello robot 2');
return;
}
}
return next();
});
app.use(function(req, res, next) {
var i, ip, _i, _ref;
ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
for (i = _i = 0, _ref = ipblack.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
if (ip.indexOf(ipblack[i]) !== -1) {
res.end(' 404');
return;
}
}
return next();
});
app.use(app.router);
rainbow.route(app, {
controllers: '/controllers/',
filters: '/filters/',
template: '/views/'
});
static_jades = {};
app.get("/:p", function(req, res, next) {
var p;
p = req.params.p;
if (static_jades[p]) {
res.render(p + ".jade");
return;
} else {
if (fs.existsSync(path.join(__dirname, 'views', p + ".jade"))) {
res.render(p + ".jade");
static_jades[p] = true;
return;
}
}
return next();
});
app.all("*", function(req, res, next) {
return res.render('404.jade', {
status: 404
}, function(error, page) {
return res.send(page, 404);
});
});
app.use(function(err, req, res, next) {
console.trace(err);
return res.render('error.jade', {
error: err.message,
code: err.code
}, function(error, page) {
return res.send(page, 404);
});
});
app.locals.moment = require('moment');
app.locals.moment.lang('zh-cn');
app.locals.pretty = true;
app.locals.stringUtil = require('./lib/string-util.coffee');
app.locals.arrayUtil = require('./lib/array-util.coffee');
app.locals.assets_head = config.assets_head;
return app.locals.assets_tm = "8-23";
});
app.configure("development", function() {
return app.use(express.errorHandler());
});
}).call(this);