-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (63 loc) · 1.75 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
const express = require("express");
const hb = require("hbs");
var exphbs = require('express-handlebars');
var path = require("path");
var product = require('./routes/product');
var chating = require('./routes/chating');
var user= require('./routes/user');
const passport= require("passport");
const bodyParser = require("body-parser");
const cookieparser = require("cookie-parser");
const expresssession = require("express-session");
const csrf=require("csurf");
const flash=require("connect-flash");
var helpers = require('handlebars-helpers')();
const app =express();
var hbs= exphbs.create({
extname:'.hbs',
defaultLayout:null ,
layoutsDir:path.join(__dirname + '/views/layouts'),
helpers: helpers,
partialsDir:[
path.join(__dirname + '/views/layouts')
],
})
const urlencoded = bodyParser.urlencoded({extended : true});
app.use(bodyParser.json());
app.use(urlencoded);
//passport config
require("./config/passportlocal")(passport);
//port config
const port =process.env.port || 3000;
app.use(express.static('views/assets/image'));
app.engine('.hbs', hbs.engine);
app.set('view engine', 'hbs');
//for auth and csrf token
app.use(cookieparser("randomKey"));
app.use(expresssession({
secret:"randomKey",
resave:true,
//save:true,
maxAge :24*60*60*1000,//milli second
}));
app.use(csrf({cookie: false,}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use((req,res,next)=>{
res.locals.error =req.flash("error");
next();
});
//router config
app.use('/product',product);
app.use('/user',user);
app.use('/chating',chating);
app.get('/',(req,res)=>{
res.render("index",{
name:"User Login",
crfToken:req.csrfToken(),
});
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})