-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (64 loc) · 2 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
const express = require('express');
// const connectDb = require('./database/database')
const user = require('./routes/user-routes')
const cart = require('./routes/cart-routes');
const store = require('./routes/store-routes');
const product = require('./routes/product-routes');
const order = require('./routes/order-routes');
const path = require('path');
const cors = require('cors');
const cookieParser = require('cookie-parser')
const session = require('express-session');
const { verifyAuth,isAdmin } = require('./middleware/authentication');
const app = express();
// Enable CORS
app.use(cors());
app.set('view engine', 'ejs');
app.set('views', './views');
app.use(express.json());
app.use(express.urlencoded({extended:true}));
app.use(cookieParser());
app.use(session({
secret: 'MXIUuw6u5Ty0Ecih3XCjZ1+0575N2OTu0x9gsOl6pBc=',
resave: false,
saveUninitialized: true,
cookie: { secure: false } // Set secure to true if using HTTPS
}));
require('dotenv').config();
// app.use("/files", express.static(path.join(__dirname, "files")));
app.use("/files", express.static(path.join(__dirname, "files")));
// for the routes
app.use('/',user);
app.use('/',product);
app.use('/stores',store);
app.use('/carts',cart);
app.use('/orders',order);
app.get('/',(req,res) => {
res.render('products');
})
app.get('/signup',(req,res) => {
res.render('signup');
})
app.get('/login', (req, res) => {
res.render('login');
});
app.get('/add/store', (req, res) => {
res.render('addStore');
});
app.get('/stores/add/products',(req,res) => {
res.render('addstoreProduct')
})
app.get('/categories',(req,res) => {
res.render('categories');
})
app.get('/logout', verifyAuth, (req, res) => {
// Set the JWT cookie's expiration time to a past date
res.cookie('jwt', '', { expires: new Date(0) });
// Remove the req.user object
delete req.user;
// Redirect the user to the login page
res.redirect('/login');
});
app.listen(8000,() => {
console.log(`Listening on port 8000`);
})