-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
92 lines (71 loc) · 2.1 KB
/
app.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
const express=require("express")
require("dotenv").config()
const session=require("express-session")
const Razorpay=require('razorpay')
const logger = require("./middleware/logger")
const path=require("path")
const cookieParser=require('cookie-parser');
const db = require('./config/config')
const app=express();
const hbs=require("hbs")
const userRouter=require("./routes/userRouter")
const adminRouter=require("./routes/adminRouter")
logger(app);
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')))
app.use(function(req, res, next) {
res.header('Cache-Control', 'no-cache, no-store');
next();
});
app.use(session({
secret:"process.env.secret",
cookie:{maxAge:600000}
}));
app.set('view engine','hbs')
app.set('views',path.join(__dirname,'views'));
hbs.registerHelper('formatDate', function(date) {
let day = ("0" + date.getDate()).slice(-2);
let month = ('0' + (date.getMonth() + 1)).slice(-2);
let year = date.getFullYear().toString();
return `${day}-${month}-${year}`;
});
hbs.registerHelper('times', function(n, block) {
var accum = '';
for(var i = 1; i <= n; ++i) {
block.data.index = i;
accum += block.fn(this);
}
return accum;
});
hbs.registerHelper('ifeq', function (a, b, options) {
if (a == b) { return options.fn(this); }
return options.inverse(this);
});
hbs.registerHelper('ifnoteq', function (a, b, options) {
if (a != b) { return options.fn(this); }
return options.inverse(this);
});
hbs.registerPartials(__dirname + '/views/layouts', function (err){});
hbs.registerPartials(__dirname + '/views/partials', function (err) {});
hbs.registerHelper("counter", function (index){
return index + 1;
});
//routers
app.use(userRouter);
app.use(adminRouter);
//port
const PORT=process.env.PORT||3002;
db.connectToDb((err)=>{
if(!err){
app.listen(PORT,()=>{
console.log(`listening in the port ${PORT}`)
})
}
});
//error
app.use(function(req, res, next) {
res.status(404).render('error/404');
});
module.exports = app;