-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (32 loc) · 1003 Bytes
/
server.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
const path = require('path')
const resolvedDirectory = path.resolve()
const express = require('express')
const cors = require('cors')
const colors = require('colors')
const morgan = require('morgan')
require('dotenv').config()
const PORT = process.env.PORT || 5000
const { notFound, errorHandler } = require('./middleware/errorMiddleware') // Middlewares
const tokenRoutes = require('./routes/metadataRoutes') // Routes
const imageRoutes = require('./routes/imageRoutes') // Routes
const app = express()
if (process.env.NODE_ENV === 'development') {
app.use(morgan('dev'))
}
app.use(cors())
app.use(express.json())
app.use('/api/metadata', tokenRoutes)
app.use('/api/image', imageRoutes)
app.use('/uploads', express.static(path.join(resolvedDirectory, '/uploads')))
app.get('/', (req, res) => {
res.send('API is running....')
})
app.use(notFound)
app.use(errorHandler)
app.listen(
PORT,
console.error(
`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`.green
.inverse
)
)