-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (54 loc) · 1.73 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import express from 'express';
import cors from 'cors';
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import helmet from 'helmet';
import bodyParser from 'body-parser';
import logger from './src/utils/logger.js';
import morgan from 'morgan';
import morganMiddleware from './src/middleware/morgan.middleware.js';
import realtorAuthRoutes from './src/routes/v1/realtor/auth.js';
import propertyRoutes from './src/routes/v1/realtor/property.js';
import publicRoutes from './src/routes/v1/user/property.js';
import adminAuthRoutes from './src/routes/v1/admin/auth.js';
import adminRoutes from './src/routes/v1/admin/property.js';
dotenv.config();
mongoose
.connect(process.env.MONGODB_URI)
.then(() => {
logger.info('Connected to MongoDB');
})
.catch((err) => {
logger.error(`Error connecting to MongoDB: ${err}`);
});
const app = express();
app.use(bodyParser.json());
app.use(express.json());
app.use(helmet());
app.use(helmet.crossOriginResourcePolicy({ policy: 'cross-origin' }));
app.use(morganMiddleware);
const corsOptions = {
origin: [
'http://localhost:5000',
'http://localhost:5173',
'https://www.skenny.org',
'http://localhost:5175',
'https://skenny-admin.vercel.app',
],
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
allowedHeaders: [
'Content-Type',
'Authorization',
'Access-Control-Allow-Credentials',
],
};
app.use(cors(corsOptions));
app.use('/api/v1/auth', realtorAuthRoutes);
app.use('/api/v1/properties', propertyRoutes);
app.use('/api/v1/users', publicRoutes);
app.use('/api/v1/admin/auth', adminAuthRoutes);
app.use('/api/v1/admin', adminRoutes);
app.listen(process.env.PORT, () => {
logger.info(`Server is running on port ${process.env.PORT}`);
});