-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (51 loc) · 1.67 KB
/
index.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
var http = require('http'),
path = require('path'),
express = require('express'),
bodyParser = require('body-parser'),
cookieParser = require('cookie-parser'),
session = require('express-session'),
mongoose = require('mongoose'),
conf = require('./conf.json'),
shared = require('./routes/shared');
/*
mongodb://username:password@host:port/database?options
*/
mongoose.connect(
'mongodb://' +
//conf.db.username + ':' +
//conf.db.password + '@' +
conf.db.host + ':' +
conf.db.port + '/' +
conf.db.database
);
// todo: http://stackoverflow.com/questions/14588032/mongoose-password-hashing
mongoose.connection.on('open', function() {
console.log('Db connection opened.');
//console.log(mongoose.connection.collection);
// mongoose.connection.db.collectionNames(function(err, names) {
// if (err) throw err;
// console.log('--->', names);
// });
});
mongoose.connection.on('error', console.error.bind(console, 'connection error:'));
var app = express();
app.set('views', './views');
app.set('view engine', 'jade');
app.engine('jade', require('jade').__express);
app.locals.title = "Your Best Car Mate";
if (app.get('env') === 'development') {
app.locals.pretty = true;
}
app.use("/public", express.static(path.join(__dirname, 'public')));
app.use(bodyParser());
app.use(cookieParser('grzybniaZPatatajnia'));
app.use(session());
// Do we still need that?
app.use(shared.clearMessages);
require('./routes/routes.js')(app);
var port = process.argv[2] || conf.general.port;
http
.createServer(app)
.listen(port, function(data) {
console.log('Express server listening on port %d.', port);
});