-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.js
61 lines (46 loc) · 1.57 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
52
53
54
55
56
57
58
59
60
61
require('dotenv').config()
require('express-async-errors');
var pjax = require('express-pjax');
const path = require('path')
//option pakages
const cookieParser = require('cookie-parser')
const express = require('express')
const app = express()
//connect database
const connectDB = require('./db/connect')
//routes
const authRouter= require('./routes/authRoutes')
const userRouter = require('./routes/userRoutes')
const productRouter = require('./routes/productRoutes')
const orderRouter = require('./routes/orderRoutes')
const hompageRouter = require('./routes/homepageRoute')
const menuRouter = require('./routes/menuRoutes')
const adminRouter = require('./routes/adminRoutes')
//middleware
const notFoundMiddleware = require('./middleware/not-found')
app.use(express.json())
app.use(cookieParser('jwtSecret'))
app.use(express.static('./public'));
app.use(express.urlencoded({extended:false}));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use('/KACoffe/v1',hompageRouter )
app.use('/KACoffe/v1/menu', menuRouter)
app.use('/KACoffe/v1/auth', authRouter)
app.use('/KACoffe/v1/user', userRouter)
app.use('/KACoffe/v1/product', productRouter)
app.use('/KACoffe/v1/order', orderRouter)
app.use('/KACoffe/v1/admin', adminRouter)
app.use(notFoundMiddleware)
const port = process.env.PORT||8080;
const start = async() => {
try {
await connectDB(process.env.MONGO_URI)
app.listen(port, (req, res) => {
console.log(`app is listening on port ${port}`)
})
} catch (error) {
console.log(error)
}
}
start()