   config = projRequire 'server/server-config'
 
   dbName = config.mongo.db
-  address = config.mongo.host + ':' + config.mongo.port
+  address = "#{config.mongo.host}:#{config.mongo.port}"
   if config.mongo.username and config.mongo.password
-    address = config.mongo.username + ':' + config.mongo.password + '@' + address
+    address = "#{config.mongo.username}:#{config.mongo.password}@#{address}"
   address = "mongodb://#{address}/#{dbName}"
   
-  log.info "Connecting to Mongo with connection string #{address}"
+  winston.info "DB connecting to #{address}"
   mongoose.connect address
-  mongoose.connection.once 'open', -> Grid.gfs = Grid(mongoose.connection.db, mongoose.mongo)
+  mongoose.connection.once 'open', -> 
+    Grid.gfs = Grid(mongoose.connection.db, mongoose.mongo)
   
   
   #- express creation, config
   express = require 'express'
   app = express()
-  app.set('port', config.port)
-  app.set('env', if config.isProduction then 'production' else 'development')
+  app.set 'port', config.port
+  app.set 'env', if config.isProduction then 'production' else 'development'
 
   
   #- express middleware

log = require 'winston'
require './projRequire'

# TOGO: Where should this go?
do (setupGlobals = this) ->
  GLOBAL._ = require 'lodash'
  _.str = require 'underscore.string'
  _.mixin _.str.exports()
  global.tv4 = require 'tv4' # required for TreemaUtils to work

module.exports.startServer = ->
  
  #- setup logging
  log.remove(log.transports.Console)
  log.add(log.transports.Console,
    colorize: true,
    timestamp: true
  )

  
  #- connect to db
  Grid = require 'gridfs-stream'

  # TODO: setup api routes

  
  #- Serve main.html
  fs = require 'graceful-fs'
  try
    mainHTML = fs.readFileSync(path.join(__dirname, '../public', 'main.html'), 'utf8')
  catch e
    log.error "Error modifying main.html: #{e}"

  app.all '*', (req, res) ->
    # insert the user object directly into the html so the application can have it immediately. Sanitize </script>
#      data = mainHTML.replace('"userObjectTag"', JSON.stringify(UserHandler.formatEntity(req, req.user)).replace(/\//g, '\\/'))
    res.header 'Cache-Control', 'no-cache, no-store, must-revalidate'
    res.header 'Pragma', 'no-cache'
    res.header 'Expires', 0
    res.send 200, mainHTML
  
  
  http = require 'http'
  http.createServer(app).listen(app.get('port'))
  winston.info('Express server listening on port ' + app.get('port'))
  app

  