-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (44 loc) · 1.33 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
require('dotenv').config();
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000
const cors = require('cors')
const mongoose = require('mongoose');
const fileUpload = require("express-fileupload");
const cloudinary = require('cloudinary').v2
const profileRouter = require('./routes/profileRouter')
const inspectionRouter = require('./routes/inspectionRouter')
const propertyRouter = require("./routes/propertyRouter");
//cloudinary config
cloudinary.config({
cloud_name: process.env.CLOUD_NAME,
api_key: process.env.CLOUD_API_KEY,
api_secret: process.env.CLOUD_API_SECRET,
});
// middlewares
app.use(fileUpload({useTempFiles: true}));
app.use(express.json());
app.use(cors());
// routes
app.get('/', (req, res) => {
res.status(200).send('Beta Home Server')
})
app.use('/api/v1', profileRouter);
app.use('/api/v1', inspectionRouter);
app.use('/api/v1/property', propertyRouter);
// error routes
app.use((req,res) => {
res.status(404).send("Resource not found")
})
// db Connections and server listening
const startServer = async () => {
try {
await mongoose.connect(process.env.MONGO_URL, { dbName: "BetaHome" });
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
} catch (error) {
console.log(error)
}
};
startServer();