-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.js
96 lines (80 loc) · 2.77 KB
/
web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, emailer = require('./routes/emailer')
, path = require('path')
, location_results = require('./routes/location_results');
var app = express();
// Configuration
app.configure(function() {
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
//app.engine('html', require('ejs').renderFile);
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
// Add mobile middleware to set a response local var that lets us check
// the user agent in views and load scripts appropriately
app.use(function(req, res, next) {
var ua = req.get('User-Agent');
if(/mobile/i.test(ua)) {
res.locals.is_mobile = true;
} else {
res.locals.is_mobile = false;
}
next();
});
app.use(require('stylus').middleware({
src: __dirname + '/assets' //.styl files are located in '/assets/stylesheets',
, dest: __dirname + '/public'//.css files compiles
, compress: true
}));
app.use(app.router);
//Note: the path '/public/stylesheets/style.css' should be '/stylesheets/style.css' with this line
app.use(express.static(path.join(__dirname, '/public')));
});
app.configure('development', function() {
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function() {
app.use(express.errorHandler());
});
//var mongoUri = 'mongodb://localhost/dormLocationDB';
//process.env.MONGOLAB_URI ||
//process.env.MONGOHQ_URL ||
//'mongodb://localhost/dormLocationDB';
//mongo.Db.connect(mongoUri, function (err, db) {
//var locations = db.locations.find();
/*console.log('herrow');
var numLocations = db.locations.count();
var locations = db.locations.find();
var minDistance = -1;
var index = -1;
for (var i = 0; i < numLocations; i++) {
var locLat = locations[i].lat;
var locLng = locations[i].lng;
var distance = pow((testLocation.lat - lat),2) + pow((testLocation.lng - lng),2);
if (minDistance > 0 && distance < minDistance) {
minDistance = distance;
index = i;
}
}
$('#building').attr('value', locations[index].name);*/
//db.collection('locations', function(err2, collection) {
//collection.find();
//});
//});
// Routes
app.get('/', routes.index);
app.get('/about', routes.about);
app.get('/contact', routes.contact);
app.get('/information', routes.information);
app.get('/success', routes.success);
app.get('/failure', routes.failure);
app.post('/email', emailer.email);
app.get('/location_results', location_results.fetchLocations);
app.listen(app.get('port'), function() {
console.log("Express server listening on port %d in %s mode", app.get('port'), app.settings.env);
});