Updated server/index.coffee for new session middleware. doesn't work
This commit is contained in:
+23
-23
@@ -2,26 +2,36 @@ http = require 'http'
|
||||
path = require 'path'
|
||||
express = require 'express'
|
||||
gzippo = require 'gzippo'
|
||||
MongoStore = require('connect-mongo')(express)
|
||||
derby = require 'derby'
|
||||
app = require '../app'
|
||||
serverError = require './serverError'
|
||||
|
||||
## RACER CONFIGURATION ##
|
||||
|
||||
racer = require 'derby/node_modules/racer'
|
||||
|
||||
racer.set('transports', ['xhr-polling'])
|
||||
|
||||
racer.set('bundle timeout', 5000)
|
||||
|
||||
## SERVER CONFIGURATION ##
|
||||
|
||||
expressApp = express()
|
||||
server = http.createServer expressApp
|
||||
module.exports = server
|
||||
|
||||
derby.use(require 'racer-db-mongo')
|
||||
store = derby.createStore
|
||||
db: {type: 'Mongo', uri: process.env.NODE_DB_URI}
|
||||
listen: server
|
||||
#require('./queries')(store)
|
||||
|
||||
ONE_YEAR = 1000 * 60 * 60 * 24 * 365
|
||||
root = path.dirname path.dirname __dirname
|
||||
publicPath = path.join root, 'public'
|
||||
|
||||
(expressApp = express())
|
||||
expressApp
|
||||
.use(express.favicon())
|
||||
# Gzip static files and serve from memory
|
||||
.use(gzippo.staticGzip publicPath, maxAge: ONE_YEAR)
|
||||
|
||||
# Gzip dynamically rendered content
|
||||
.use(express.compress())
|
||||
|
||||
@@ -29,37 +39,27 @@ publicPath = path.join root, 'public'
|
||||
# .use(express.bodyParser())
|
||||
# .use(express.methodOverride())
|
||||
|
||||
# Derby session middleware creates req.model and subscribes to _session
|
||||
.use(express.cookieParser 'secret_sauce')
|
||||
.use(express.session
|
||||
secret: 'secret_sauce'
|
||||
# Uncomment and supply secret to add Derby session handling
|
||||
# Derby session middleware creates req.session and socket.io sessions
|
||||
.use(express.cookieParser())
|
||||
.use(store.sessionMiddleware
|
||||
secret: process.env.SESSION_SECRET || 'YOUR SECRET HERE'
|
||||
cookie: {maxAge: ONE_YEAR}
|
||||
store: new MongoStore(url: process.env.NODE_DB_URI, collection: 'express-sessions')
|
||||
)
|
||||
.use(app.session())
|
||||
|
||||
# The router method creates an express middleware from the app's routes
|
||||
# Adds req.getModel method
|
||||
.use(store.modelMiddleware())
|
||||
# Creates an express middleware from the app's routes
|
||||
.use(app.router())
|
||||
.use(expressApp.router)
|
||||
.use(serverError root)
|
||||
|
||||
exports = module.exports = server = http.createServer expressApp
|
||||
|
||||
|
||||
## SERVER ONLY ROUTES ##
|
||||
|
||||
expressApp.all '*', (req) ->
|
||||
throw "404: #{req.url}"
|
||||
|
||||
|
||||
## STORE SETUP ##
|
||||
|
||||
derby.use(require 'racer-db-mongo')
|
||||
|
||||
exports.store = app.createStore
|
||||
listen: server
|
||||
db: {type: 'Mongo', uri: process.env.NODE_DB_URI}
|
||||
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user