| 1 | require('dotenv').config({ path: require('path').resolve(__dirname, '../.env') }); |
| 2 | |
| 3 | const express = require('express'); |
| 4 | const path = require('path'); |
| 5 | const morgan = require('morgan'); |
| 6 | const cors = require('cors'); |
| 7 | const http = require('http'); |
| 8 | const db = require('./db'); |
| 9 | |
| 10 | const app = express(); |
| 11 | const server = http.createServer(app); |
| 12 | const corsOptions = { |
| 13 | origin: 'http://localhost:3000', |
| 14 | methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', |
| 15 | credentials: true, |
| 16 | optionsSuccessStatus: 204, |
| 17 | }; |
| 18 | |
| 19 | app.use(express.static(path.join(__dirname, 'uploads'))); |
| 20 | app.use(express.json()); |
| 21 | app.use(express.urlencoded({ extended: true })); |
| 22 | app.use(cors(corsOptions)); |
| 23 | |
| 24 | |
| 25 | const users = require('./routes/users'); |
| 26 | const auth = require('./routes/auth'); |
| 27 | const common = require('./routes/common'); |
| 28 | const property = require('./routes/property'); |
| 29 | const email = require('./routes/email'); |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | app.get('/', (req, res) => {res.status(200).send('Success');}); |
| 54 | |
| 55 | |
| 56 | app.use('/api/user', users); |
| 57 | app.use('/api/auth', auth); |
| 58 | app.use('/api/common', common); |
| 59 | app.use('/api/property', property); |
| 60 | app.use('/api/email', email); |
| 61 | |
| 62 | |
| 63 | const PORT = process.env.PORT || 5001; |
| 64 | |
| 65 | server.listen(PORT, () => { |
| 66 | console.log(`Server running on port ${PORT}`); |
| 67 | }); |