-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfigure.js
32 lines (29 loc) · 1.09 KB
/
configure.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
var express = require('express')
, _ = require('underscore')
module.exports = function( server ) {
server.use( express.bodyParser() )
server.use( express.cookieParser() )
server.use( '/javascript', express.static( __dirname + '/javascript' ))
server.use( '/css', express.static( __dirname + '/css' ))
server.set( 'view options', { layout: false } )
server.set( 'views', __dirname + '/' )
server.register( '.html', {
compile: function (str, options) {
_.templateSettings = {
interpolate : /\{\{-([\s\S]+?)\}\}/g
, escape : /\{\{([^-]|[^-][\s\S]+?)\}\}/g
, evaluate : /\{\[([\s\S]+?)\]\}/g
}
var template = _.template(str)
return function (locals) {
return template(locals)
}
}
})
server.use( function( req, res, next ) {
req.session = JSON.parse(req.cookies[ 'sid' ] || '{}' )
res.on('header', function() { res.cookie( 'sid', JSON.stringify(req.session) ) })
next()
})
return server
}