project-knedita/src/app.ts

38 lines
852 B
TypeScript
Raw Normal View History

2023-06-20 20:05:15 +00:00
import 'dotenv/config'
import compression from 'compression'
import cors from 'cors'
2023-06-20 20:05:15 +00:00
import express from 'express'
import limiter from 'middlewares/rate-limit'
import morganMiddleware from 'middlewares/morgan'
import router from './routes'
2023-06-20 20:05:15 +00:00
const app = express()
// TODO: test socket io, emit notifications when create one.
// TODO: start to create the client, or a barebone to test socket io
2023-06-20 20:05:15 +00:00
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(morganMiddleware)
2023-09-03 19:54:55 +00:00
app.options('*', cors())
app.use(
cors({
credentials: true,
2023-09-03 15:58:09 +00:00
origin: process.env.CLIENT_URL,
2023-09-03 19:54:55 +00:00
methods: ['GET', 'POST', 'PUT'],
optionsSuccessStatus: 200,
}),
)
2023-09-03 19:54:55 +00:00
app.use(limiter)
app.use(router)
app.use(compression({ level: 9 }))
2023-06-20 20:05:15 +00:00
app.use((_req, res) => {
res.status(404).json({
error: 'Endpoint not found',
2023-06-20 20:05:15 +00:00
})
})
export default app