-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (47 loc) · 1.46 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
const express = require('express')
const app = express()
const router = express.Router();
const bodyParser = require('body-parser')
const cors = require('cors')
const port = process.env.PORT || 8000;
const scrapeHome = require('./service/scrapeHome');
const query = require('./service/query');
const searchDetails = require('./service/searchDetails')
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
//Routes
router.get('/', async (req, res) => {
console.log('Home page loader hitted!')
const response = await scrapeHome();
if(response.error) {
return response.error;
}
console.log("RESPONSE RETURNED")
res.send(response);
})
router.post('/search', async function(req, res) {
const response = await query(req.body);
if(!response || !response.success) {
res.json({
success: false,
message: "Could not find the search result"
})
}else{
res.send(response)
}
})
router.get('/details',async function(req, res) {
if(req.query.hasOwnProperty('zip') && req.query.hasOwnProperty('property_address')) {
const response = await searchDetails(req.query);
if(response && response.success){
res.send(response)
}
return{
success: false,
message: "Could not find the search details"
}
}
})
app.use('/', router)
app.listen(port, () => console.log(`Test app listening on port ${port}!`))