-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
96 lines (80 loc) · 3.64 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const expressEdge = require('express-edge')
const mongoose = require('mongoose')
const bodyParser = require ('body-parser')
const fileUpload = require('express-fileupload')
const express = require('express')
const expressSession = require('express-session')
const connectMongo = require('connect-mongo')
const connectFlash = require('connect-flash')
const edge = require('edge.js')
const insertItemController = require('./controllers/insertItem')
const homePageController = require('./controllers/homePage')
const postItemController = require('./controllers/postItem')
const getItemController = require('./controllers/getItem')
const registerController = require('./controllers/register')
const createUserController = require('./controllers/createUser')
const loginController = require('./controllers/login')
const signInUserController = require('./controllers/signInUser')
const logoutController = require('./controllers/logout')
const addToCartController = require('./controllers/addToCart')
const storeTransactionController = require('./controllers/storeTransaction')
const cartController = require('./controllers/cart')
const isRegisteredController = require('./controllers/isRegistered')
const removeFromCartController = require('./controllers/removeFromCart')
const updateCartController = require('./controllers/updateCart')
const purchaseHistoryController = require ('./controllers/purchaseHistory')
const updateItemController = require ('./controllers/updateItem')
const editItemController = require ('./controllers/editItem')
const deleteItemController = require ('./controllers/deleteItem')
const inventoryController = require ('./controllers/inventory')
const searchNfilterController = require('./controllers/searchNfilter')
const getFilterController = require('./controllers/getFilters')
const app = new express()
mongoose.connect('mongodb://localhost/Grocerrs')
app.use(fileUpload())
app.use(express.static('public'))
app.use(expressEdge)
app.set('views',`${__dirname}/views`)
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended : true }))
app.use(connectFlash())
const mongoStore = connectMongo(expressSession)
app.use(expressSession({
secret:'secret',
store: new mongoStore({
mongooseConnection : mongoose.connection
})
}))
app.use('*',(req,res,next)=>{
edge.global('auth',req.session.userId)
next()
})
const auth = require('./middleware/auth')
const redirectOnAuth = require('./middleware/redirectOnAuth')
const postItem = require('./middleware/postItem')
app.get('/',homePageController)
app.get('/insertItem',auth,insertItemController)
app.get('/item/:id',getItemController)
app.get('/register',redirectOnAuth,registerController)
app.get('/login',redirectOnAuth,loginController)
app.get('/logout',auth,logoutController)
app.get('/cart',cartController)
app.get('/isRegistered/:id',isRegisteredController)
app.get('/purchaseHistory',purchaseHistoryController)
app.get('/updateItem/:id',updateItemController)
app.get('/deleteItem/:id',deleteItemController)
app.get('/inventory',inventoryController)
app.get('/searchNfilter/:search/:brand/:category/:minPrice/:maxPrice',searchNfilterController)
app.get('/getFilters',getFilterController)
app.post('/postItem',postItem,postItemController)
app.post('/createUser',redirectOnAuth,createUserController)
app.post('/signInUser',redirectOnAuth,signInUserController)
app.post('/addToCart',addToCartController)
app.post('/storeTransaction',storeTransactionController)
app.post('/removeFromCart',removeFromCartController)
app.post('/updateCart',updateCartController)
app.post('/editItem',editItemController)
app.use((req,res)=>res.render('notFound'))
app.listen(4000,()=>{
console.log("App Listening")
})