-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (30 loc) · 943 Bytes
/
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
import express from 'express'
import morgan from 'morgan'
import cors from 'cors'
import checkoutRoutes from './routes/checkout.js'
import productsRoutes from './routes/products.js'
import categoriesRoutes from './routes/categories.js'
import oauthRoutes from './routes/oauth.js'
const app = express()
const port = process.env.PORT || 8000
app.use(morgan('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(
cors({
origin: 'http://localhost:3000',
})
)
app.use('/api/v1/categories', categoriesRoutes)
app.use('/api/v1/products', productsRoutes)
app.use('/api/v1/checkout', checkoutRoutes)
app.use('/oauth', oauthRoutes)
// Catch Express Errors
app.use((err, req, res, next) => {
const { message = 'Something went wrong', statusCode = 500 } = err
console.log(err)
res.status(statusCode).send(message)
})
app.listen(port, () => {
console.log(`Listening on http://localhost:${port}`)
})