   console.log 'album', path
   getAlbum(path).then (album) ->
     respondJSON res, 200, album.toObject()
+  .fail (e) ->
+    console?.error e
+    respond500 res
   .done()
 
 if require.main is module

  else
    next()

albumQuery = (path) ->
  $or: [
    { path },
    { 'pictures.path': path }
  ]

exports.app = app = express()
#app.use connect.compress()
app.use app.router
app.use express.static(staticPath, maxAge: 24*60*60*1000)
app.use indexHtmlAnyway

_          = require 'underscore'
path       = require 'path'
express    = require 'express'
config     = require '../server_config.json'
{getAlbum} = require './services/album_service.coffee'
unusedConn = require './db'

staticPath = path.resolve path.dirname(module.filename), '..', 'public'
indexHtml  = path.resolve staticPath, 'index.html'

respondModel = (res, model) ->
  return respond404 res unless model
  respondJSON res, 200, _.omit(model.toObject(), '_id')

respondJSON = (res, code, model) ->
  res.contentType 'application/json'
  res.send code, JSON.stringify data

respond404 = (res) ->
  respondJSON res, 404,
    error: 404
    message: 'Not found'

respond500 = (res) ->
  respond500 res, 500,
    error: 500
    message: 'Internal server error'

indexHtmlAnyway = (req, res, next) ->
  if req.accepts 'html'
