-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
32 lines (27 loc) · 854 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
const express = require('express');
const cors = require('cors');
const { connectDB } = require('./config/database');
const authRoute = require('./routes/authRoute');
const { errorHandler } = require('./middlewares/error');
const compression = require('compression');
const helmet = require('helmet');
const ApiError = require('./util/ApiError');
const { NOT_FOUND } = require('./util/errorMessages');
const app = express();
connectDB();
app.use(
cors({
origin: ['http://localhost:5173', 'http://localhost:3000', '*'],
})
);
app.use(helmet());
app.use(compression());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use('/auth/v1', authRoute);
app.use((req, res, next) => {
const { code, name, message } = NOT_FOUND;
next(new ApiError(code, message, name));
});
app.use(errorHandler);
module.exports = app;