-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (43 loc) · 1.54 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
//requires
const express = require("express");
const path = require("path");
const app = express();
const session = require("express-session");
const SessionStore = require("connect-mongodb-session")(session) ;
const flash = require("connect-flash") ;
//require from midleWare
const homeRoute = require("./routes/homeRoute");
const productRoute = require("./routes/productRoute");
const authRoute = require("./routes/authRoute");
const cardRoute = require("./routes/cardRoute");
const OrderRoute = require("./routes/orderRoute");
const AdminRoute = require("./routes/adminRoute")
//require from midleWare
app.use(express.static(path.join(__dirname, "assats"))) ;
app.use(express.static(path.join(__dirname, "images"))) ;
app.use(flash())
//start session
const Store = new SessionStore({
uri :"mongodb://localhost:27017/onlineShop" ,
collection : "Sessions"
}) ;
app.use(session({
secret :"this is the secret" ,
saveUninitialized : false ,
store : Store
}))
app.set('view engine' , 'ejs') ;
app.set('views' , 'views') ;
let bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({extended : false }));
app.use(homeRoute);
app.use(productRoute);
app.use(authRoute);
app.use(cardRoute);
app.use(OrderRoute);
app.use(AdminRoute);
app.get("/notAdmin" ,(req , res , next )=>{
res.status(404);
res.render("notAdmin.ejs" ,{ isUser : req.session.isUser , isAdmin :req.session.isAdmin ,pageTitle : 'not Admin'})
})
app.listen(1000 , console.log("server is running now on the port 1000"));