-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·99 lines (81 loc) · 3.02 KB
/
Copy pathapp.js
File metadata and controls
executable file
·99 lines (81 loc) · 3.02 KB
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
var express = require('express'),
posts = require('./routes/posts.js'),
path = require('path'),
moment = require('moment'),
marked = require('marked'),
preload = require('./preload/preload.js'),
passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
login = require('./routes/login.js'),
github = require('./routes/github.js'),
request = require('request'),
config = require('./config/config.js'),
hl = require("highlight").Highlight;
var app = express();
app.configure(function() {
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
app.use(express.logger('dev'));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session({secret: config.web.sessionSecret}));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
marked.setOptions({
highlight: function(code, lang) {
return hl(code);
}
});
posts.config = config;
app.locals.fromNow = function(d) { return moment(d).fromNow(); };
app.locals.url = function(post) {
return (post.type === 'post' ? '/' + moment(post.created).format('YYYY/MM/DD') : '') + '/' + post.slug;
};
app.locals.marked = function(md) { return marked(md); };
app.locals.config = config.site;
preload.preload();
});
passport.use(new LocalStrategy(login.localStrategy));
passport.serializeUser(function(user, done) {
console.log('serializing user: ' + JSON.stringify(user));
done(null, user.username);
});
passport.deserializeUser(function(username, done) {
console.log('deserializing user: ' + username);
done(null, {username: username});
});
app.all('/admin(/*)?', login.requiresLogin);
app.get('/login', login.login);
app.post('/login',
passport.authenticate('local', { failureRedirect: '/login' }),
function(req, res) { res.redirect(req.get('referrer')); });
app.get('/', posts.index);
app.get('/:year/:month/:day/:slug', posts.view);
app.get('/admin/posts/add', posts.add);
app.post('/admin/posts/add', posts.newPost);
app.get('/tags', posts.tags);
app.get('/commits', github.publicActivity);
app.get('/:slug', posts.viewPage);
app.listen(config.web.port, function(){
console.log("Expressive listening on port " + config.web.port);
setInterval(function() {
var url = config.web.github.url;
var redis = require('redis');
var redisClient = redis.createClient();
redisClient.on('connect', function() {
request(url, function (error, response, body) {
redisClient.set('github:commits', body, redis.print);
redisClient.quit(function(err, res) {
console.log('closing redis client.');
});
});
});
redisClient.on('error', function (err) {
console.error('Error occurred trying to retrieve github activity: ' + err);
});
}, config.web.github.intervalInMillis);
});