forked from twinlabs/forum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
96 lines (81 loc) · 2.61 KB
/
app.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
var application_helper = require('./lib/helpers');
var express = require('express');
var http = require('http');
var app = express();
var session = require('express-session');
var lessMiddleware = require('less-middleware');
var autoprefixer = require('autoprefixer-core');
var httpServer = http.createServer(app);
var passport = require('passport');
var pg = require('pg');
var pgSession = require('connect-pg-simple')(session);
rootRequire('config/environments')(app);
app.set('io', require('socket.io').listen(httpServer));
var conString = process.env.DATABASE_URL || "postgres://postgres@localhost/forum";
app.use(express.compress());
app.use(express.cookieParser());
app.use(session({
store: new pgSession({
pg: pg,
conString: conString,
tableName: 'session'
}),
secret: app.get('sessionSecret') || 'w!** *1*h',
cookie: { maxAge: 365 * 24 * 60 * 60 * 1000 } // 1 year
}));
rootRequire('lib/authentication');
app.use(passport.initialize());
app.use(passport.session());
app.use(express.bodyParser());
rootRequire('config/routes')(app, passport);
var clientConstants = {
socketAddress: app.get('hostName')
};
app.locals.clientConstants = JSON.stringify(clientConstants);
app.engine('jade', require('jade').__express);
app.set('views', process.cwd() + '/app/views');
app.set('view engine', 'jade');
app.locals.basedir = process.cwd() + '/app/views';
app.use('/templates/post', express.static(__dirname + '/app/views/posts/'));
app.use(lessMiddleware(__dirname + '/app/assets', {
postprocess: {
css: function(css, request){
return autoprefixer.process(css).css;
}
}
}));
app.use(express.static(__dirname + '/app/assets'));
module.exports = {
server: httpServer.listen(app.get('PORT'), function(){
console.log('listening on port ' + app.get('PORT'));
}),
io: app.get('io'),
app: app,
port: app.get('PORT')
};
app.locals.moment = require('moment');
app.locals.marked = require('marked');
app.locals.getPostDate = application_helper.getPostDate;
var markedRenderer = new app.locals.marked.Renderer();
markedRenderer.link = function(href, title, text) {
return '<a target="_blank"' +
'href="' + href + '"' +
(title ? 'title="' + title + '"' : '') +
'>' + text + "</a>";
};
app.locals.marked.setOptions({
emoji: function (emoji) {
return '<img src="'
+ 'http://cloud.ahfr.org/images/emoji/'
+ encodeURIComponent(emoji)
+ '.png"'
+ ' alt=":'
+ escape(emoji)
+ ':"'
+ ' title=":'
+ escape(emoji)
+ ':"'
+ ' class="emoji" align="absmiddle" height="20" width="20">';
},
renderer: markedRenderer
});