2023-06-20 20:05:15 +00:00
|
|
|
import 'dotenv/config'
|
|
|
|
|
2023-08-05 19:51:43 +00:00
|
|
|
import compression from 'compression'
|
|
|
|
import cors from 'cors'
|
2023-06-20 20:05:15 +00:00
|
|
|
import express from 'express'
|
2023-08-05 19:51:43 +00:00
|
|
|
import limiter from 'middlewares/rate-limit'
|
|
|
|
import morganMiddleware from 'middlewares/morgan'
|
2023-06-23 18:15:11 +00:00
|
|
|
import router from './routes'
|
2023-06-20 20:05:15 +00:00
|
|
|
|
|
|
|
const app = express()
|
|
|
|
|
|
|
|
app.use(express.json())
|
|
|
|
app.use(express.urlencoded({ extended: true }))
|
2023-08-05 19:51:43 +00:00
|
|
|
app.use(morganMiddleware)
|
2023-07-17 20:47:05 +00:00
|
|
|
app.use(limiter)
|
2023-08-05 19:51:43 +00:00
|
|
|
app.use(router)
|
2023-06-20 20:05:15 +00:00
|
|
|
app.use(compression({ level: 9 }))
|
2023-08-05 19:51:43 +00:00
|
|
|
app.use(cors({
|
|
|
|
credentials: true,
|
|
|
|
origin: '*', // TODO: Add client development (and production too) url
|
|
|
|
optionsSuccessStatus: 200
|
|
|
|
}))
|
2023-06-20 20:05:15 +00:00
|
|
|
|
|
|
|
app.use((_req, res) => {
|
|
|
|
res.status(404).json({
|
|
|
|
error: 'Not found'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
export default app
|