-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
85 lines (73 loc) · 2.13 KB
/
app.js
File metadata and controls
85 lines (73 loc) · 2.13 KB
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
var express = require('express'),
http = require('http'),
path = require('path'),
passport = require("passport");
var pg = require('pg');
var conString = "postgres://wu:@localhost/wu";
var env = process.env.NODE_ENV || 'development',
config = require('./config/config')[env];
require('./config/passport')(passport, config);
var bodyParser = require('body-parser');
var app = express();
app.configure(function () {
app.set('port', config.app.port);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(express.cookieParser());
//app.use(express.bodyParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.session(
{
secret: 'this shit hits'
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function () {
console.log ("Development mode.");
app.use(express.errorHandler());
});
app.configure ('production', function () {
console.log ("Production mode.");
});
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('500', { error: err });
});
app.use(function(req, res, next){
res.status(404);
if (req.accepts('html')) {
res.render('404',
{
url : req.url
});
return;
}
if (req.accepts('json')) {
res.send({ error: 'Not found' });
return;
}
res.type('txt').send('Not found');
});
var client = new pg.Client(conString);
client.connect(function(err) {
if(err) {
return console.error('could not connect to postgres', err);
}
client.query('SELECT NOW() AS "theTime"', function(err, result) {
if(err) {
return console.error('error running query', err);
}
console.log(result.rows[0].theTime);
//output: Tue Jan 15 2013 19:12:47 GMT-600 (CST)
client.end();
});
});
require('./config/routes')(app, config, passport, pg, conString);
http.createServer(app).listen(app.get('port'), function () {
console.log("Express server listening on port " + app.get('port'));
});