-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.js
76 lines (76 loc) · 1.58 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
67
68
69
70
71
72
73
74
75
76
/**
* Create express object.
*/
var express = require('express');
/**
* Session object declear
*/
var session = require('express-session');
/**
* Cookie object declear
*/
var cookieParser = require('cookie-parser');
/**
* Create app object & assign express object.
*/
var app = express();
/**
* Create reload object.
*/
var reload = require('reload');
/**
* For set port or default 7000 posr.
*/
app.set('port', process.env.POST || 7000);
/**
* Set view engine & point a view folder.
*/
app.set('view engine', 'ejs');
app.set('views', 'views');
/**
* Register cookie
*/
app.use(cookieParser());
/**
* Register session with secret key
*/
app.use(session({secret: 'kak'}));
/**
* Add & register body parser
*/
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
/**
* Set site title.
*/
app.locals.siteTitle = 'Ecommerce';
/**
* set public folder is static to use any where.
* Public folder contents js, css, images
*/
app.use(express.static('public'));
/**
* Add routes.
*/
app.use(require('./routers/pages'));
/**
* Cache
*/
/*app.use(function (req, res, next) {
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
// -1 setting up request as expired and re-requesting before display again.
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
next();
});*/
/**
* Create server.
*/
var server = app.listen(7000, function() {
console.log('Running server');
})
/**
* Auto reload server.
*/
reload(server, app);