2013-08-29 03:21:06 +00:00
|
|
|
require('coffee-script') // remove this once we've fully converted over
|
|
|
|
|
|
|
|
|
|
var express = require("express");
|
|
|
|
|
var http = require("http");
|
|
|
|
|
var path = require("path");
|
|
|
|
|
var app = express();
|
|
|
|
|
var nconf = require('nconf');
|
2013-09-03 01:38:05 +00:00
|
|
|
var middleware = require('./middleware');
|
2013-08-29 03:21:06 +00:00
|
|
|
var server;
|
2013-09-03 23:22:16 +00:00
|
|
|
var TWO_WEEKS = 1000 * 60 * 60 * 24 * 14;
|
2013-08-29 03:21:06 +00:00
|
|
|
|
|
|
|
|
// Setup configurations
|
|
|
|
|
require('./config');
|
|
|
|
|
require('./errors');
|
|
|
|
|
|
|
|
|
|
// MongoDB Configuration
|
|
|
|
|
mongoose = require('mongoose');
|
|
|
|
|
require('./models/user'); //load up the user schema - TODO is this necessary?
|
|
|
|
|
require('./models/group');
|
|
|
|
|
mongoose.connect(nconf.get('NODE_DB_URI'), function(err) {
|
|
|
|
|
if (err) throw err;
|
|
|
|
|
console.info('Connected with Mongoose');
|
|
|
|
|
});
|
|
|
|
|
|
2013-09-03 23:22:16 +00:00
|
|
|
/**
|
2013-08-29 03:21:06 +00:00
|
|
|
Server Configuration
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// all environments
|
|
|
|
|
app.set("port", nconf.get('PORT'));
|
|
|
|
|
app.set("views", __dirname + "/../views");
|
|
|
|
|
app.set("view engine", "jade");
|
|
|
|
|
app.use(express.favicon());
|
|
|
|
|
app.use(express.logger("dev"));
|
2013-09-03 01:38:05 +00:00
|
|
|
app.use(middleware.cors);
|
2013-08-29 03:21:06 +00:00
|
|
|
app.use(express.bodyParser());
|
|
|
|
|
app.use(require('connect-assets')());
|
|
|
|
|
app.use(express.methodOverride());
|
2013-09-03 01:38:05 +00:00
|
|
|
//app.use(express.cookieParser(nconf.get('SESSION_SECRET')));
|
|
|
|
|
app.use(express.cookieParser());
|
2013-09-03 23:22:16 +00:00
|
|
|
app.use(express.cookieSession({ secret: nconf.get('SESSION_SECRET'), httpOnly: false, cookie: { maxAge: TWO_WEEKS }}));
|
2013-09-03 01:38:05 +00:00
|
|
|
//app.use(express.session());
|
|
|
|
|
app.use(middleware.splash);
|
|
|
|
|
app.use(middleware.locals);
|
2013-08-29 03:21:06 +00:00
|
|
|
app.use(app.router);
|
|
|
|
|
app.use(express['static'](path.join(__dirname, "/../public")));
|
|
|
|
|
|
|
|
|
|
// development only
|
|
|
|
|
if ("development" === app.get("env")) {
|
|
|
|
|
app.use(express.errorHandler());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Custom Directives
|
|
|
|
|
app.use(require('./routes/pages').middleware);
|
|
|
|
|
app.use('/api/v1', require('./routes/api').middleware);
|
|
|
|
|
app.use(require('./controllers/deprecated').middleware);
|
|
|
|
|
server = http.createServer(app).listen(app.get("port"), function() {
|
|
|
|
|
return console.log("Express server listening on port " + app.get("port"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = server;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
#ONE_YEAR = 1000 * 60 * 60 * 24 * 365
|
|
|
|
|
#root = path.dirname path.dirname __dirname
|
|
|
|
|
#publicPath = path.join root, 'public'
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
#expressApp
|
|
|
|
|
# .use(middleware.allowCrossDomain)
|
|
|
|
|
# .use(express.favicon("#{publicPath}/favicon.ico"))
|
|
|
|
|
# # Gzip static files and serve from memory
|
|
|
|
|
# .use(gzippo.staticGzip(publicPath, maxAge: ONE_YEAR))
|
|
|
|
|
# # Gzip dynamically rendered content
|
|
|
|
|
# .use(express.compress())
|
|
|
|
|
# .use(middleware.translate)
|
|
|
|
|
# .use(middleware.view)
|
|
|
|
|
# .use(auth.middleware(strategies, options))
|
|
|
|
|
# # Creates an express middleware from the app's routes
|
|
|
|
|
# .use(app.router())
|
|
|
|
|
# .use(require('./static').middleware)
|
|
|
|
|
# .use(expressApp.router)
|
|
|
|
|
# .use(serverError(root))
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
## Errors
|
|
|
|
|
#expressApp.all '*', (req) ->
|
|
|
|
|
# throw "404: #{req.url}"
|
|
|
|
|
*/
|
|
|
|
|
|