From 41feba721acca4830b8921024c5735e7f82ed56b Mon Sep 17 00:00:00 2001 From: Alexandr Pokutnik Date: Sat, 30 Mar 2013 20:37:24 +0200 Subject: [PATCH] move logging to utils --- api_srv/app.coffee | 10 ++++++---- api_srv/utils.coffee | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/api_srv/app.coffee b/api_srv/app.coffee index 2e34238a..a08d1d28 100644 --- a/api_srv/app.coffee +++ b/api_srv/app.coffee @@ -18,13 +18,13 @@ app.configure -> app.use express.methodOverride() app.use express.cookieParser('secret') app.use express.session() + + app.use utils.sessionLogging + app.use app.router app.use require('less-middleware')({ src: __dirname + '/public' }) app.use express.static(path.join(__dirname, 'public')) -app.configure 'development', -> - app.use(express.errorHandler()) - app.get '/', routes.index app.get '/users', user.list @@ -35,13 +35,15 @@ app.get '/api/', (req, res) -> res.send api app.post '/api/', (req, res) -> + api = utils.loadjson './public/api/index.json' req.session.email = req.body.email - res.send req.session + res.send api app.get '/api/voices/', (req, res) -> res.sendfile './public/api/voices/index.json' + console.log req.session http.createServer(app).listen app.get('port'), -> console.log "Express server listening on port " + app.get('port') diff --git a/api_srv/utils.coffee b/api_srv/utils.coffee index 890ee366..86768f64 100644 --- a/api_srv/utils.coffee +++ b/api_srv/utils.coffee @@ -4,4 +4,9 @@ module.exports = { loadjson: (path) -> data = fs.readFileSync path, 'utf8' JSON.parse(data) + + sessionLogging: (req, res, next) -> + console.log '%s %s', req.method, req.url + console.log req.session + next() }