-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (37 loc) · 1.49 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
require('dotenv').config();
var express = require('express');
var cookieParser = require('cookie-parser')
var mongoose = require('mongoose');
mongoose.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useFindAndModify: false,
useCreateIndex: true,
useUnifiedTopology: true
});
var userRoute = require('./routes/user.route');
var authRoute = require('./routes/auth.route');
var productRoute = require('./routes/product.route');
var cartRoute = require('./routes/cart.route');
var authMiddlelware = require('./middlewares/auth.middleware');
var sessionMiddleware = require('./middlewares/session.middleware');
var apiProductRoute = require('./api/routes/product.route')
var port = process.env.PORT || 3100;
var app = express();
app.set('view engine', 'pug')
app.set('views', './views')
app.use(express.json()) // for parsing application/json
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
app.use('/api/products', apiProductRoute)
app.use(cookieParser(process.env.SESSION_SECRET));
app.use(sessionMiddleware);
app.get('/', (req, res) => {
res.render('index')
});
app.use(express.static('public'))
app.use('/users', authMiddlelware.requireAuth, userRoute);
app.use('/auth', authRoute);
app.use('/products', authMiddlelware.requireAuth, productRoute)
app.use('/cart', authMiddlelware.requireAuth, cartRoute)
app.listen(port, () => {
console.log('Server listening on port ', port)
});