-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
61 lines (53 loc) · 1.65 KB
/
Copy pathserver.js
File metadata and controls
61 lines (53 loc) · 1.65 KB
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
// Importing required modules
const express = require('express')
const path = require('path')
require('dotenv').config();
// Importing all utilities that need to be use
const authRoutes = require('./routes/authRoutes')
const addproduct = require('./routes/productRoutes')
const cartRoutes = require('./routes/cartRoutes')
const orderRoutes = require('./routes/orderRoutes')
const app = express()
// Using this middleware to parse req.body in json format
app.use(express.json())
// setting views and view engine
// Setting view engine tp ejs files
app.set("view engine", "ejs")
// setting path for ejs files
app.set("views", path.join("./Frontend/views"))
// Setting path to render css
app.use(express.static(path.join(__dirname)));
const port = process.env.PORT || 8080
app.get('/',(req,res)=>{
res.render('home')
})
app.get('/auth',(req,res)=>{
res.render('auth')
})
app.get('/cart',(req,res)=>{
res.render('cart')
})
app.get('/orders',(req,res)=>{
res.render('orders')
})
app.get('/checkout',(req,res)=>{
res.render('checkout')
})
app.get('/product/webpage/:productId',(req,res)=>{
res.render('product',{productId: req.params.productId})
})
app.get('/shop',(req,res)=>{
res.render("shop")
})
// Using auth routes in our server files which take access from routes folder
app.use(authRoutes)
// Exposing end points to add product in the product database,this can only be used the people with admin perms
app.use(addproduct)
// Exposing cart API
app.use(cartRoutes)
// Exposing apis required to place and track order
app.use(orderRoutes)
// Listening on port defined in .env files else on port 8080
app.listen(port, () => {
console.log(`Listening on port ${port}`)
})