-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (31 loc) · 1.24 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
const express = require('express')
const bodyParser = require('body-parser')
const path = require('path')
require('express-group-routes')
// Controllers
const UserController = require('./controllers/user')
const KostController = require('./controllers/kost')
// Middlewares
const { authenticated } = require('./middleware/auth')
// config
const kostUpload = require('./middleware/kost-upload')
const app = express()
const port = process.env.PORT || 3000
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use("/images", express.static(path.join(__dirname, "images")));
app.group('/api', (router) => {
// User Route
router.get('/users', UserController.index)
router.get('/user/me', authenticated, UserController.show)
// Auth Route
router.post('/login', UserController.login)
router.post('/register', UserController.register)
// Kos Route
router.get('/kost', KostController.index)
router.get('/kost/:id', KostController.show)
router.post('/kost', authenticated, kostUpload, KostController.store)
router.patch('/kost/:id', authenticated, KostController.update)
router.delete('/kost/:id', authenticated, KostController.destroy)
})
app.listen(port, () => console.log(`Sedang berjalan di port ${port}`))