-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
112 lines (98 loc) · 2.97 KB
/
app.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const mindsdb = require("./api/mindsdb");
const logger = require("./logger");
const app = express();
// Middleware to parse request body
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Serve the static files in public directory
app.use(express.static("public"));
// Connect to MindsDB and start the server when connection is established
mindsdb
.connectToMindsDB()
.then(() => {
app.listen(3000, () => {
logger.info("Server listening on port 3000");
});
})
.catch((err) => {
logger.error("Error connecting to MindsDB: ", err);
});
// Route for the homepage
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
});
app.post("/destinations", async (req, res) => {
const inputCountry = req.body.inputCountry;
const inputInterest = req.body.inputInterest;
const inputSeason = req.body.inputSeason;
const inputBudget = req.body.inputBudget;
try {
// Call a function from mindsdb.js
const destination = await mindsdb.curateDestination(
inputCountry,
inputInterest,
inputSeason,
inputBudget
);
res.status(200).send(destination);
} catch (error) {
logger.error("Error curating destinations: ", error);
res
.status(500)
.send({ error: "An error occurred while curating destinations." });
}
});
app.post("/itinerary", async (req, res) => {
const inputDestination = req.body.inputDestination;
const inputDuration = req.body.inputDuration;
try {
// Call a function from mindsdb.js
const itinerary = await mindsdb.generateItinerary(
inputDestination,
inputDuration
);
res.status(200).send(itinerary);
} catch (error) {
logger.error("Error generating Itinerary: ", error);
res
.status(500)
.send({ error: "An error occurred while generating Itinerary." });
}
});
app.post("/accomodation", async (req, res) => {
const inputDestination = req.body.inputDestination;
const inputType = req.body.inputType;
try {
// Call a function from mindsdb.js
const accomodation = await mindsdb.selectAccomodation(
inputDestination,
inputType
);
res.status(200).send(accomodation);
} catch (error) {
logger.error("Error finding the best accomodation: ", error);
res
.status(500)
.send({ error: "An error occurred while finding the best accomodation." });
}
});
app.post("/explore", async (req, res) => {
const inputDestination = req.body.inputDestination;
const choice = req.body.selectedChoice;
try {
// Call a function from mindsdb.js
const exploration = await mindsdb.exploreOptions(
inputDestination,
choice
);
res.status(200).send(exploration);
} catch (error) {
logger.error("Error exploring the best options: ", error);
res
.status(500)
.send({ error: "An error occurred while exploring the best options." });
}
});