forked from btply/nodeshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshop.js
60 lines (47 loc) · 1.63 KB
/
shop.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
// Require express
var express = require('express');
// Set up express
var app = express();
// Require mongostore session storage
var mongoStore = require('connect-mongo')(express);
var passport = require('passport');
// Require needed files
var database = require('./shop/data');
var config = require('./shop/config.json');
var info = require('./package.json');
console.log('NodeShop Started!');
// Connect to database
database.startup(config.connection);
console.log('Connecting to database...');
// Configure Express
app.configure(function(){
// Set up jade
app.set('views', __dirname + '/shop/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.cookieParser());
app.use(express.bodyParser());
// Set up sessions
app.use(express.session({
// Set up MongoDB session storage
store: new mongoStore({url:config.connection}),
// Set session to expire after 21 days
cookie: { maxAge: new Date(Date.now() + 181440000)},
// Get session secret from config file
secret: config.cookie_secret
}));
// Set up passport
app.use(passport.initialize());
app.use(passport.session());
// Define public assets
app.use(express.static(__dirname + '/shop/public'));
});
// Require router, passing passport for authenticating pages
require('./shop/router')(app, passport);
// Listen for requests
app.listen(process.env.PORT);
console.log('NodeShop v' + info.version + ' listening on port ' + process.env.PORT);
// Handle all uncaught errors
process.on('uncaughtException', function(err) {
console.log(err);
});