-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (49 loc) · 1.88 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
58
59
60
61
62
63
64
65
66
67
const express = require("express");
const cors = require("cors");
const path = require("path");
const redis = require("redis");
const app = express();
app.use(express.json());
const PORT = process.env.PORT || 3000;
//importing residential, commercial and condos routes
const residentialRoutes = require("./Routes/residential");
const commercialRoutes = require("./Routes/commercial");
//importing getLatLong routes
const getLatLongRoutes = require("./Routes/getLatLong");
//Importing property search routes
const propertySearchRoutes = require("./Routes/propertySearch")
// Create Redis client
const redisClient = redis.createClient();
redisClient.on("error", (error) => console.error(`Redis Error: ${error}`));
redisClient.connect();
// Create Redis client for get-lat-long routes with a different database
const getLatLongRedisClient = redis.createClient();
getLatLongRedisClient.on("error", (error) => console.error(`GetLatLong Redis Error: ${error}`));
getLatLongRedisClient.connect();
getLatLongRedisClient.select(1);
// Pass the Redis client to the routes
app.use((req, res, next) => {
req.redisClient = redisClient;
req.getLatLongRedisClient = getLatLongRedisClient;
next();
});
//make residential images available
app.use(
"/residentialPhotos",
express.static(path.join(__dirname, "./Data/ResidentialAndCondos/Photos/"))
);
//make commercial images available
app.use(
"/commercialPhotos",
express.static(path.join(__dirname, "./Data/Commercial/Photos/"))
);
//Seperating routes into residential, commercial and condos
app.use("/residential", residentialRoutes);
app.use("/commercial", commercialRoutes);
//Integrating get-lat-long-queue
app.use("/get-lat-long", cors(), getLatLongRoutes);
//Integreate search
app.use("/propertySearch", propertySearchRoutes)
app.listen(PORT, () => {
console.log(`${new Date(Date.now()).toLocaleString()}: Server running on port: ${PORT}`);
});