-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
54 lines (42 loc) · 1.76 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
//=============================================================================
// Basic Config
//=============================================================================
const express = require('express')
// instantiate express
const app = express()
app.set('port', process.env.PORT || 8000)
const cors = require('cors')
app.use(cors())
//=============================================================================
// Middleware
//=============================================================================
// `express.json` parses application/json request data and
// adds it to the request object as request.body
app.use(express.json())
// `express.urlencoded` parses x-ww-form-urlencoded request data and
// adds it to the request object as request.body
app.use(express.urlencoded({ extended: true }))
//=============================================================================
// ROUTES
//=============================================================================
// Redirect
app.get('/', (req, res) => {
res.redirect('/api/bookmarks')
})
/* START CONTROLLERS HERE */
const bookmarksController = require('./controllers/bookmarksController')
app.use('/api/bookmarks/', bookmarksController)
const usersController = require('./controllers/usersController')
app.use('/api/users/', usersController)
/* END CONTROLLERS HERE */
app.use((err, req, res, next) => {
const statusCode = res.statusCode || 500
const message = err.message || 'Internal Server Error'
res.status(statusCode).send(message)
})
//=============================================================================
// START SERVER
//=============================================================================
app.listen(app.get('port'), () => {
console.log(`✅ PORT: ${app.get('port')} 🌟`)
})