mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -05:00
29 lines
No EOL
925 B
CoffeeScript
29 lines
No EOL
925 B
CoffeeScript
config = require '../../server_config'
|
|
winston = require 'winston'
|
|
mongoose = require 'mongoose'
|
|
Grid = require 'gridfs-stream'
|
|
|
|
testing = '--unittest' in process.argv
|
|
|
|
|
|
module.exports.connect = () ->
|
|
address = module.exports.generateMongoConnectionString()
|
|
|
|
winston.info "Connecting to standalone server #{address}"
|
|
mongoose.connect address
|
|
mongoose.connection.once 'open', ->
|
|
Grid.gfs = Grid(mongoose.connection.db, mongoose.mongo)
|
|
|
|
|
|
module.exports.generateMongoConnectionString = ->
|
|
if config.mongo.mongoose_replica_string
|
|
address = config.mongo.mongoose_replica_string
|
|
else
|
|
dbName = config.mongo.db
|
|
dbName += '_unittest' if testing
|
|
address = config.mongo.host + ":" + config.mongo.port
|
|
if config.mongo.username and config.mongo.password
|
|
address = config.mongo.username + ":" + config.mongo.password + "@" + address
|
|
address = "mongodb://#{address}/#{dbName}"
|
|
|
|
return address |