| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | var express = require('express'), | 
					
						
							| 
									
										
										
										
											2013-04-22 15:17:41 -04:00
										 |  |  | 	WebServer = express(), | 
					
						
							|  |  |  | 	server = require('http').createServer(WebServer), | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  |     connect = require('connect'), | 
					
						
							| 
									
										
										
										
											2013-04-22 15:17:41 -04:00
										 |  |  |     config = require('../config.js'); | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | (function(app) { | 
					
						
							|  |  |  | 	var templates = global.templates; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-23 19:38:48 +00:00
										 |  |  | 	function refreshTemplates() { | 
					
						
							|  |  |  | 		//need a better solution than copying this code on every call. is there an "onconnect" event?
 | 
					
						
							|  |  |  | 		if (DEVELOPMENT === true) { | 
					
						
							|  |  |  | 			// refreshing templates
 | 
					
						
							|  |  |  | 			modules.templates.init(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 	app.get('/', function(req, res) { | 
					
						
							| 
									
										
										
										
											2013-04-23 19:38:48 +00:00
										 |  |  | 		refreshTemplates(); | 
					
						
							| 
									
										
										
										
											2013-04-22 14:37:13 -04:00
										 |  |  | 		res.send(templates['header'] + templates['home'] + templates['footer']); | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-22 19:01:45 +00:00
										 |  |  | 	app.get('/login', function(req, res) { | 
					
						
							| 
									
										
										
										
											2013-04-23 19:38:48 +00:00
										 |  |  | 		refreshTemplates(); | 
					
						
							| 
									
										
										
										
											2013-04-22 17:31:51 -04:00
										 |  |  | 		res.send(templates['header'] + templates['login'] + templates['footer']); | 
					
						
							| 
									
										
										
										
											2013-04-22 19:01:45 +00:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-23 16:18:43 -04:00
										 |  |  | 	app.get('/reset/:code', function(req, res) { | 
					
						
							|  |  |  | 		refreshTemplates(); | 
					
						
							|  |  |  | 		res.send(templates['header'] + templates['reset_code'] + templates['footer']); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-22 17:31:51 -04:00
										 |  |  | 	app.get('/reset', function(req, res) { | 
					
						
							| 
									
										
										
										
											2013-04-23 19:38:48 +00:00
										 |  |  | 		refreshTemplates(); | 
					
						
							| 
									
										
										
										
											2013-04-22 17:31:51 -04:00
										 |  |  | 		res.send(templates['header'] + templates['reset'] + templates['footer']); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	app.get('/register', function(req, res) { | 
					
						
							| 
									
										
										
										
											2013-04-23 19:38:48 +00:00
										 |  |  | 		refreshTemplates(); | 
					
						
							| 
									
										
										
										
											2013-04-22 14:37:13 -04:00
										 |  |  | 		res.send(templates['header'] + templates['register'] + templates['footer']); | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module.exports.init = function() { | 
					
						
							|  |  |  | 		// todo move some of this stuff into config.json
 | 
					
						
							|  |  |  | 		app.configure(function() { | 
					
						
							| 
									
										
										
										
											2013-04-23 15:39:23 -04:00
										 |  |  | 			app.use(express.favicon());	// 2 args: string path and object options (i.e. expire time etc)
 | 
					
						
							|  |  |  | 			app.use(express.bodyParser());	// Puts POST vars in request.body
 | 
					
						
							|  |  |  | 			app.use(express.cookieParser());	// Presumably important
 | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			// Dunno wtf this does
 | 
					
						
							| 
									
										
										
										
											2013-04-23 12:06:22 -04:00
										 |  |  | 			// app.use(express.logger({ format: '\x1b[1m:method\x1b[0m \x1b[33m:url\x1b[0m :response-time ms' }));
 | 
					
						
							| 
									
										
										
										
											2013-04-23 15:39:23 -04:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			// Useful if you want to use app.put and app.delete (instead of app.post all the time)
 | 
					
						
							| 
									
										
										
										
											2013-04-23 12:06:22 -04:00
										 |  |  | 			// app.use(express.methodOverride());
 | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 			app.use(express.static(global.configuration.ROOT_DIRECTORY + '/public'));  | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }(WebServer)); | 
					
						
							| 
									
										
										
										
											2013-04-22 15:17:41 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | server.listen(config.port); | 
					
						
							| 
									
										
										
										
											2013-04-22 15:23:02 -04:00
										 |  |  | global.server = server; |