| 
									
										
										
										
											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-28 13:58:19 -04:00
										 |  |  | 	RedisStore = require('connect-redis')(express), | 
					
						
							|  |  |  | 	path = require('path'), | 
					
						
							| 
									
										
										
										
											2013-05-01 12:54:04 -04:00
										 |  |  |     config = require('../config.js'), | 
					
						
							|  |  |  |     redis = require('redis'), | 
					
						
							| 
									
										
										
										
											2013-05-01 21:03:37 -04:00
										 |  |  | 	redisServer = redis.createClient(config.redis.port, config.redis.host, config.redis.options), | 
					
						
							| 
									
										
										
										
											2013-05-09 06:26:32 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-05-04 18:20:22 -04:00
										 |  |  | 	user = require('./user.js'), | 
					
						
							| 
									
										
										
										
											2013-05-14 13:04:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-14 12:13:29 -04:00
										 |  |  | 	categories = require('./categories.js'), | 
					
						
							|  |  |  | 	posts = require('./posts.js'), | 
					
						
							|  |  |  | 	topics = require('./topics.js'), | 
					
						
							| 
									
										
										
										
											2013-05-04 18:20:22 -04:00
										 |  |  | 	utils = require('./utils.js'), | 
					
						
							| 
									
										
										
										
											2013-05-11 21:55:14 -04:00
										 |  |  | 	fs = require('fs'), | 
					
						
							| 
									
										
										
										
											2013-05-09 03:33:53 +00:00
										 |  |  | 	admin = require('./routes/admin.js'), | 
					
						
							| 
									
										
										
										
											2013-05-14 13:04:12 -04:00
										 |  |  | 	userRoute = require('./routes/user.js'), | 
					
						
							| 
									
										
										
										
											2013-05-09 06:26:32 +00:00
										 |  |  | 	auth = require('./routes/authentication.js'); | 
					
						
							| 
									
										
										
										
											2013-05-02 15:57:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | (function(app) { | 
					
						
							|  |  |  | 	var templates = global.templates; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 16:42:12 -04:00
										 |  |  | 	// Middlewares
 | 
					
						
							|  |  |  | 	app.use(express.favicon());	// 2 args: string path and object options (i.e. expire time etc)
 | 
					
						
							| 
									
										
										
										
											2013-05-02 09:40:44 -04:00
										 |  |  | 	app.use(require('less-middleware')({ src: path.join(__dirname, '../', '/public') })); | 
					
						
							| 
									
										
										
										
											2013-04-28 13:58:19 -04:00
										 |  |  | 	app.use(express.static(path.join(__dirname, '../', 'public'))); | 
					
						
							| 
									
										
										
										
											2013-04-24 16:42:12 -04:00
										 |  |  | 	app.use(express.bodyParser());	// Puts POST vars in request.body
 | 
					
						
							|  |  |  | 	app.use(express.cookieParser());	// If you want to parse cookies (res.cookies)
 | 
					
						
							| 
									
										
										
										
											2013-04-28 13:58:19 -04:00
										 |  |  | 	app.use(express.compress()); | 
					
						
							| 
									
										
										
										
											2013-04-25 11:15:03 -04:00
										 |  |  | 	app.use(express.session({ | 
					
						
							| 
									
										
										
										
											2013-04-25 12:59:31 -04:00
										 |  |  | 		store: new RedisStore({ | 
					
						
							| 
									
										
										
										
											2013-05-01 12:54:04 -04:00
										 |  |  | 			client: redisServer, | 
					
						
							| 
									
										
										
										
											2013-04-25 12:59:31 -04:00
										 |  |  | 			ttl: 60*60*24*14 | 
					
						
							|  |  |  | 		}), | 
					
						
							| 
									
										
										
										
											2013-05-01 16:27:57 -04:00
										 |  |  | 		secret: config.secret, | 
					
						
							| 
									
										
										
										
											2013-04-25 11:15:03 -04:00
										 |  |  | 		key: 'express.sid' | 
					
						
							|  |  |  | 	})); | 
					
						
							| 
									
										
										
										
											2013-05-09 06:26:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	auth.initialize(app); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-25 12:59:31 -04:00
										 |  |  | 	app.use(function(req, res, next) { | 
					
						
							| 
									
										
										
										
											2013-04-28 13:58:19 -04:00
										 |  |  | 		// Don't bother with session handling for API requests
 | 
					
						
							| 
									
										
										
										
											2013-04-28 22:26:27 -04:00
										 |  |  | 		if (/^\/api\//.test(req.url)) return next(); | 
					
						
							| 
									
										
										
										
											2013-04-28 21:15:47 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 21:03:37 -04:00
										 |  |  | 		if (req.user && req.user.uid) { | 
					
						
							| 
									
										
										
										
											2013-05-14 12:13:29 -04:00
										 |  |  | 			user.session_ping(req.sessionID, req.user.uid); | 
					
						
							| 
									
										
										
										
											2013-04-25 12:59:31 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-28 13:58:19 -04:00
										 |  |  | 		// (Re-)register the session as active
 | 
					
						
							| 
									
										
										
										
											2013-05-14 12:13:29 -04:00
										 |  |  | 		user.active.register(req.sessionID); | 
					
						
							| 
									
										
										
										
											2013-04-28 13:58:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-25 12:59:31 -04:00
										 |  |  | 		next(); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2013-05-07 10:56:30 -04:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-05-09 06:26:32 +00:00
										 |  |  | 	auth.create_routes(app); | 
					
						
							|  |  |  | 	admin.create_routes(app); | 
					
						
							| 
									
										
										
										
											2013-05-14 13:04:12 -04:00
										 |  |  | 	userRoute.create_routes(app); | 
					
						
							| 
									
										
										
										
											2013-04-25 19:13:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 09:13:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 06:26:32 +00:00
										 |  |  | 	app.create_route = function(url, tpl) { // to remove
 | 
					
						
							| 
									
										
										
										
											2013-05-07 21:29:28 +00:00
										 |  |  | 		return '<script>templates.ready(function(){ajaxify.go("' + url + '", null, "' + tpl + '");});</script>'; | 
					
						
							| 
									
										
										
										
											2013-05-09 06:26:32 +00:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2013-05-07 21:29:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-03 21:19:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 22:19:54 +00:00
										 |  |  | 	// Basic Routes (entirely client-side parsed, goal is to move the rest of the crap in this file into this one section)
 | 
					
						
							|  |  |  | 	(function() { | 
					
						
							| 
									
										
										
										
											2013-05-09 06:26:32 +00:00
										 |  |  | 		var routes = ['', 'login', 'register', 'account', 'latest', 'popular', 'active', '403']; | 
					
						
							| 
									
										
										
										
											2013-04-25 21:55:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 22:19:54 +00:00
										 |  |  | 		for (var i=0, ii=routes.length; i<ii; i++) { | 
					
						
							|  |  |  | 			(function(route) { | 
					
						
							| 
									
										
										
										
											2013-05-06 14:27:15 -04:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2013-05-01 22:19:54 +00:00
										 |  |  | 				app.get('/' + route, function(req, res) { | 
					
						
							| 
									
										
										
										
											2013-05-06 14:27:15 -04:00
										 |  |  | 					 | 
					
						
							|  |  |  | 					if ((route === 'login' || route ==='register') && (req.user && req.user.uid > 0)) { | 
					
						
							|  |  |  | 						res.redirect('/account'); | 
					
						
							|  |  |  | 						return; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					 | 
					
						
							| 
									
										
										
										
											2013-05-09 06:26:32 +00:00
										 |  |  | 					res.send(templates['header'] + app.create_route(route) + templates['footer']); | 
					
						
							| 
									
										
										
										
											2013-05-01 22:19:54 +00:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}(routes[i])); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}()); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-05-03 21:19:28 +00:00
										 |  |  | 	// Complex Routes
 | 
					
						
							|  |  |  | 	app.get('/topic/:topic_id/:slug?', function(req, res) { | 
					
						
							| 
									
										
										
										
											2013-05-07 19:22:38 +00:00
										 |  |  | 		var topic_url = req.params.topic_id + (req.params.slug ? '/' + req.params.slug : ''); | 
					
						
							|  |  |  | 		res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("topic/' + topic_url + '");});</script>' + templates['footer']); | 
					
						
							| 
									
										
										
										
											2013-05-03 21:19:28 +00:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2013-04-25 21:55:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 22:05:42 +00:00
										 |  |  | 	app.get('/category/:category_id/:slug?', function(req, res) { | 
					
						
							| 
									
										
										
										
											2013-05-07 19:22:38 +00:00
										 |  |  | 		var category_url = req.params.category_id + (req.params.slug ? '/' + req.params.slug : ''); | 
					
						
							|  |  |  | 		res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("category/' + category_url + '");});</script>' + templates['footer']); | 
					
						
							| 
									
										
										
										
											2013-05-06 22:05:42 +00:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-05 13:05:05 -04:00
										 |  |  | 	app.get('/confirm/:code', function(req, res) { | 
					
						
							| 
									
										
										
										
											2013-05-07 19:22:38 +00:00
										 |  |  | 		res.send(templates['header'] + '<script>templates.ready(function(){ajaxify.go("confirm/' + req.params.code + '");});</script>' + templates['footer']); | 
					
						
							| 
									
										
										
										
											2013-05-05 13:05:05 -04:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2013-05-09 06:26:32 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-05-03 21:19:28 +00:00
										 |  |  | 	// These functions are called via ajax once the initial page is loaded to populate templates with data
 | 
					
						
							| 
									
										
										
										
											2013-05-09 06:26:32 +00:00
										 |  |  | 	function api_method(req, res) {		 | 
					
						
							| 
									
										
										
										
											2013-05-14 14:04:19 -04:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2013-04-25 19:13:23 +00:00
										 |  |  | 		switch(req.params.method) { | 
					
						
							|  |  |  | 			case 'home' : | 
					
						
							| 
									
										
										
										
											2013-05-14 12:13:29 -04:00
										 |  |  | 					categories.get(function(data) { | 
					
						
							| 
									
										
										
										
											2013-04-25 19:13:23 +00:00
										 |  |  | 						res.send(JSON.stringify(data)); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2013-05-02 16:36:26 +00:00
										 |  |  | 			case 'login' : | 
					
						
							|  |  |  | 					var data = {}, | 
					
						
							| 
									
										
										
										
											2013-05-09 06:26:32 +00:00
										 |  |  | 						login_strategies = auth.get_login_strategies(), | 
					
						
							| 
									
										
										
										
											2013-05-02 16:36:26 +00:00
										 |  |  | 						num_strategies = login_strategies.length; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					if (num_strategies == 0) { | 
					
						
							|  |  |  | 						data = { | 
					
						
							|  |  |  | 							'login_window:spansize': 'span12', | 
					
						
							|  |  |  | 							'alternate_logins:display': 'none' | 
					
						
							|  |  |  | 						};	 | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						data = { | 
					
						
							|  |  |  | 							'login_window:spansize': 'span6', | 
					
						
							|  |  |  | 							'alternate_logins:display': 'block' | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						for (var i=0, ii=num_strategies; i<ii; i++) { | 
					
						
							| 
									
										
										
										
											2013-05-02 14:47:00 -04:00
										 |  |  | 							data[login_strategies[i] + ':display'] = 'active'; | 
					
						
							| 
									
										
										
										
											2013-05-02 16:36:26 +00:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-05-02 19:48:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 14:16:33 -04:00
										 |  |  | 					res.send(JSON.stringify(data)); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 'register' : | 
					
						
							|  |  |  | 					var data = {}, | 
					
						
							|  |  |  | 						login_strategies = auth.get_login_strategies(), | 
					
						
							|  |  |  | 						num_strategies = login_strategies.length; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					if (num_strategies == 0) { | 
					
						
							|  |  |  | 						data = { | 
					
						
							|  |  |  | 							'register_window:spansize': 'span12', | 
					
						
							|  |  |  | 							'alternate_logins:display': 'none' | 
					
						
							|  |  |  | 						};	 | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						data = { | 
					
						
							|  |  |  | 							'register_window:spansize': 'span6', | 
					
						
							|  |  |  | 							'alternate_logins:display': 'block' | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						for (var i=0, ii=num_strategies; i<ii; i++) { | 
					
						
							|  |  |  | 							data[login_strategies[i] + ':display'] = 'active'; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 16:36:26 +00:00
										 |  |  | 					res.send(JSON.stringify(data)); | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2013-05-01 21:26:47 +00:00
										 |  |  | 			case 'topic' : | 
					
						
							| 
									
										
										
										
											2013-05-14 12:13:29 -04:00
										 |  |  | 					posts.get(function(data) { | 
					
						
							| 
									
										
										
										
											2013-05-01 21:26:47 +00:00
										 |  |  | 						res.send(JSON.stringify(data)); | 
					
						
							| 
									
										
										
										
											2013-05-04 06:01:06 +00:00
										 |  |  | 					}, req.params.id, (req.user) ? req.user.uid : 0); | 
					
						
							| 
									
										
										
										
											2013-05-01 21:26:47 +00:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2013-05-06 22:05:42 +00:00
										 |  |  | 			case 'category' : | 
					
						
							| 
									
										
										
										
											2013-05-14 12:13:29 -04:00
										 |  |  | 					topics.get(function(data) { | 
					
						
							| 
									
										
										
										
											2013-05-06 22:05:42 +00:00
										 |  |  | 						res.send(JSON.stringify(data)); | 
					
						
							| 
									
										
										
										
											2013-05-09 07:27:55 +00:00
										 |  |  | 					}, req.params.id, (req.user) ? req.user.uid : 0); | 
					
						
							| 
									
										
										
										
											2013-05-06 22:05:42 +00:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2013-05-07 16:52:35 +00:00
										 |  |  | 			case 'latest' : | 
					
						
							| 
									
										
										
										
											2013-05-14 12:13:29 -04:00
										 |  |  | 					topics.get(function(data) { | 
					
						
							| 
									
										
										
										
											2013-05-07 16:52:35 +00:00
										 |  |  | 						res.send(JSON.stringify(data)); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 'popular' : | 
					
						
							| 
									
										
										
										
											2013-05-14 12:13:29 -04:00
										 |  |  | 					topics.get(function(data) { | 
					
						
							| 
									
										
										
										
											2013-05-07 16:52:35 +00:00
										 |  |  | 						res.send(JSON.stringify(data)); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 'active' : | 
					
						
							| 
									
										
										
										
											2013-05-14 12:13:29 -04:00
										 |  |  | 					topics.get(function(data) { | 
					
						
							| 
									
										
										
										
											2013-05-07 16:52:35 +00:00
										 |  |  | 						res.send(JSON.stringify(data)); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2013-05-05 13:05:05 -04:00
										 |  |  | 			case 'confirm': | 
					
						
							| 
									
										
										
										
											2013-05-14 12:13:29 -04:00
										 |  |  | 					user.email.confirm(req.params.id, function(data) { | 
					
						
							| 
									
										
										
										
											2013-05-05 13:05:05 -04:00
										 |  |  | 						if (data.status === 'ok') { | 
					
						
							|  |  |  | 							res.send(JSON.stringify({ | 
					
						
							|  |  |  | 								'alert-class': 'alert-success', | 
					
						
							|  |  |  | 								title: 'Email Confirmed', | 
					
						
							|  |  |  | 								text: 'Thank you for vaidating your email. Your account is now fully activated.' | 
					
						
							|  |  |  | 							})); | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							res.send(JSON.stringify({ | 
					
						
							|  |  |  | 								'alert-class': 'alert-error', | 
					
						
							|  |  |  | 								title: 'An error occurred...', | 
					
						
							|  |  |  | 								text: 'There was a problem validating your email address. Perhaps the code was invalid or has expired.' | 
					
						
							|  |  |  | 							})); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2013-04-25 19:13:23 +00:00
										 |  |  | 			default : | 
					
						
							|  |  |  | 				res.send('{}'); | 
					
						
							| 
									
										
										
										
											2013-04-28 13:28:20 -04:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2013-04-25 19:13:23 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-01 21:26:47 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-07 21:17:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-01 21:26:47 +00:00
										 |  |  | 	app.get('/api/:method', api_method); | 
					
						
							|  |  |  | 	app.get('/api/:method/:id', api_method); | 
					
						
							| 
									
										
										
										
											2013-05-07 21:17:22 +00:00
										 |  |  | 	// ok fine MUST ADD RECURSION style. I'll look for a better fix in future but unblocking baris for this:
 | 
					
						
							|  |  |  | 	app.get('/api/:method/:id/:section?', api_method); | 
					
						
							| 
									
										
										
										
											2013-05-01 21:26:47 +00:00
										 |  |  | 	app.get('/api/:method/:id*', api_method); | 
					
						
							| 
									
										
										
										
											2013-05-06 10:05:00 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-09 10:20:25 -04:00
										 |  |  | 	app.get('/test', function(req, res) { | 
					
						
							| 
									
										
										
										
											2013-05-14 12:13:29 -04:00
										 |  |  | 		posts.getRawContent(11, function(post) { | 
					
						
							| 
									
										
										
										
											2013-05-09 10:20:25 -04:00
										 |  |  | 			res.send(JSON.stringify(post)); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2013-05-15 15:42:24 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//START TODO: MOVE TO GRAPH.JS 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	app.get('/graph/users/:username/picture', function(req, res) { | 
					
						
							|  |  |  | 		user.get_uid_by_username(req.params.username, function(uid) { | 
					
						
							| 
									
										
										
										
											2013-05-15 15:55:39 -04:00
										 |  |  | 			if (uid == null) { | 
					
						
							|  |  |  | 				res.send('{status:0}'); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-15 15:42:24 -04:00
										 |  |  | 			user.getUserField(uid, 'picture', function(picture) { | 
					
						
							| 
									
										
										
										
											2013-05-15 15:55:39 -04:00
										 |  |  | 				if (picture == null) res.redirect('http://www.gravatar.com/avatar/a938b82215dfc96c4cabeb6906e5f953'); | 
					
						
							| 
									
										
										
										
											2013-05-15 15:42:24 -04:00
										 |  |  | 				res.redirect(picture); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//END TODO: MOVE TO GRAPH.JS
 | 
					
						
							| 
									
										
										
										
											2013-04-22 16:51:32 +00:00
										 |  |  | }(WebServer)); | 
					
						
							| 
									
										
										
										
											2013-04-22 15:17:41 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | server.listen(config.port); | 
					
						
							| 
									
										
										
										
											2013-04-22 15:23:02 -04:00
										 |  |  | global.server = server; |