-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (67 loc) · 2.84 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
require('dotenv').config()
const responseStandard = require('./src/helpers/response.js')
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const cors = require('cors')
/* ------------------------------------ */
/* -----------middleware untuk otentikasi user------------- */
// const jwt = require('jsonwebtoken')
/* ------------------------------------ */
// process.env.SECRET_KEY = 'secret'
/* ------------------------------------ */
// module middleware node
app.use(bodyParser.urlencoded({
extended: false
}))
app.use(cors())
app.use(bodyParser.json())
// provide static file
app.use('/uploads', express.static('assets/uploads')) // untuk bisa diakses secara static melalui browser
// middleware
const authMiddleware = require('./src/middleware/auth')
// IMPORT ROUTES FOR MANAGE
const manageRoles = require('./src/routes/admin/managesRoles')
const manageUsers = require('./src/routes/admin/managesUser')
const manageProduct = require('./src/routes/admin/manageProduct')
const manageCondition = require('./src/routes/admin/manageCondition')
const manageCategory = require('./src/routes/admin/manageCategory')
const colorProduct = require('./src/routes/admin/productColor')
const imageProduct = require('./src/routes/admin/productImage')
const ratingRouter = require('./src/routes/admin/rating')
// Define Routes for manage, admin responsible for this routes
app.use('/manage/roles', authMiddleware.authUser, manageRoles)
app.use('/manage/users', manageUsers)
app.use('/manage/product', manageProduct) // authMiddleware.authUser,
app.use('/manage/color', colorProduct)
app.use('/manage/condition', manageCondition)
app.use('/manage/category', manageCategory)
app.use('/manage/image', imageProduct)
app.use('/manage/rating', ratingRouter)
// auth
const authRouter = require('./src/routes/auth')
// routes auth
app.use('/auth', authRouter)
// Routes for user
const address = require('./src/routes/user/addressRoute')
const cartRouter = require('./src/routes/user/cart')
const transactionRouter = require('./src/routes/user/transactions')
const customerRouter = require('./src/routes/user/customer')
const ordersRouter = require('./src/routes/user/orders')
// routes for customer who have account
app.use('/profile', customerRouter)
app.use('/transaction', transactionRouter)
app.use('/user/cart', authMiddleware.authUser, cartRouter)
app.use('/users/address', authMiddleware.authUser, address)
app.use('/order', authMiddleware.authUser, ordersRouter)
// routes
const publicRoute = require('./src/routes/public/publicRoutes.js')
// public routes
app.use('/public', publicRoute)
// Error 404 Pages
app.get('*', (req, res) => {
responseStandard(res, 'Route Not Found', {}, 404, false)
})
app.listen(8080, () => {
console.log('App Listening on port 8080')
})