2012-04-27 02:19:31 +00:00
|
|
|
http = require 'http'
|
|
|
|
|
path = require 'path'
|
|
|
|
|
express = require 'express'
|
|
|
|
|
gzippo = require 'gzippo'
|
2012-05-02 18:49:18 +00:00
|
|
|
MongoStore = require('connect-mongo')(express)
|
2012-04-27 02:19:31 +00:00
|
|
|
derby = require 'derby'
|
|
|
|
|
app = require '../app'
|
|
|
|
|
serverError = require './serverError'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## SERVER CONFIGURATION ##
|
|
|
|
|
|
|
|
|
|
ONE_YEAR = 1000 * 60 * 60 * 24 * 365
|
|
|
|
|
root = path.dirname path.dirname __dirname
|
|
|
|
|
publicPath = path.join root, 'public'
|
|
|
|
|
|
|
|
|
|
(expressApp = express())
|
|
|
|
|
.use(express.favicon())
|
|
|
|
|
# Gzip static files and serve from memory
|
|
|
|
|
.use(gzippo.staticGzip publicPath, maxAge: ONE_YEAR)
|
|
|
|
|
|
|
|
|
|
# Gzip dynamically rendered content
|
|
|
|
|
.use(express.compress())
|
|
|
|
|
|
|
|
|
|
# Uncomment to add form data parsing support
|
|
|
|
|
# .use(express.bodyParser())
|
|
|
|
|
# .use(express.methodOverride())
|
|
|
|
|
|
|
|
|
|
# Derby session middleware creates req.model and subscribes to _session
|
2012-05-02 18:49:18 +00:00
|
|
|
.use(express.cookieParser 'secret_sauce')
|
|
|
|
|
.use(express.session
|
2012-07-09 20:59:10 +00:00
|
|
|
secret: 'secret_sauce'
|
2012-05-02 18:49:18 +00:00
|
|
|
cookie: {maxAge: ONE_YEAR}
|
2012-07-09 23:58:29 +00:00
|
|
|
store: new MongoStore(url: 'mongodb://test:test@staff.mongohq.com:10024/habitrpg', collection: 'express-sessions')
|
2012-05-02 18:49:18 +00:00
|
|
|
)
|
|
|
|
|
.use(app.session())
|
2012-04-27 02:19:31 +00:00
|
|
|
|
|
|
|
|
# The router method creates an express middleware from the app's routes
|
|
|
|
|
.use(app.router())
|
|
|
|
|
.use(expressApp.router)
|
|
|
|
|
.use(serverError root)
|
|
|
|
|
|
2012-06-28 18:44:33 +00:00
|
|
|
exports = module.exports = server = http.createServer expressApp
|
2012-04-27 02:19:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
## SERVER ONLY ROUTES ##
|
|
|
|
|
|
|
|
|
|
expressApp.all '*', (req) ->
|
|
|
|
|
throw "404: #{req.url}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## STORE SETUP ##
|
|
|
|
|
|
2012-04-27 17:04:20 +00:00
|
|
|
derby.use(require 'racer-db-mongo')
|
|
|
|
|
|
2012-06-28 18:44:33 +00:00
|
|
|
exports.store = app.createStore
|
2012-04-27 17:04:20 +00:00
|
|
|
listen: server
|
2012-07-09 23:58:29 +00:00
|
|
|
db: {type: 'Mongo', uri: 'mongodb://test:test@staff.mongohq.com:10024/habitrpg'}
|
2012-06-28 02:43:07 +00:00
|
|
|
|
|
|
|
|
# Would implement cron here, using node-cron & https://github.com/codeparty/derby/issues/99#issuecomment-6596460
|
|
|
|
|
# But it's not working
|
|
|
|
|
# cronJob = require("cron").CronJob
|
|
|
|
|
# model = store.createModel()
|
|
|
|
|
# new cronJob("* * * * * *", ->
|
|
|
|
|
# model.get() #TODO this returns {}, can't seem to access the data
|
|
|
|
|
# , null, true, "America/Los_Angeles")
|
|
|
|
|
|