-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
105 lines (78 loc) · 2.33 KB
/
server.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
const bodyParser = require("body-parser");
const express = require("express");
const server = express();
const axios = require('axios');
const port = 3000;
//Static files
server.use(express.static("public"));
server.use(bodyParser.urlencoded({ extended: true }));
server.use("/css", express.static(__dirname + "/public/css"));
server.use("/js", express.static(__dirname + "/public/js"));
server.use("/img", express.static(__dirname + "/public/img"));
server.get("/", (req, res) => {
res.sendFile(__dirname + "/views/index.html");
});
server.get("/waterconditions", (req, res) => {
res.sendFile(__dirname + "/views/waterconditions.html");
});
server.get("/fishinmyarea", (req, res) => {
res.sendFile(__dirname + "/views/fishinmyarea.html");
});
server.get("/castingtips", (req, res) => {
res.sendFile(__dirname + "/views/castingtips.html");
});
server.get("/fishfound", (req, res) => {
res.sendFile(__dirname + "/views/fishfound.html");
});
server.get("/clearwater", (req, res) => {
res.sendFile(__dirname + "/views/clearwater.html");
});
server.get("/murkywater", (req, res) => {
res.sendFile(__dirname + "/views/murkywater.html");
});
server.get("/greenwater", (req, res) => {
res.sendFile(__dirname + "/views/greenwater.html");
});
server.get("/brownwater", (req, res) => {
res.sendFile(__dirname + "/views/brownwater.html");
});
server.get('/fetch-data', async (req, res) => {
try {
const response = await axios.get('http://localhost:3001');
const data = response.data;
res.send(data);
} catch (error) {
res.status(500).send('Error fetching data.');
}
});
async function getData() {
const url = 'http://localhost:3001/';
try {
const response = await axios.get(url);
console.log('Response:', response.data);
}catch(error) {
console.error('Error:', error.message);
}
}
server.post("/Submit", (req, res) => {
const waterColor = req.body["water-color"];
switch (waterColor) {
case "clear":
res.redirect("/clearwater");
break;
case "murky":
res.redirect("/murkywater");
break;
case "green":
res.redirect("/greenwater");
break;
case "brown":
res.redirect("/brownwater");
break;
default:
res.redirect('/');
}
});
server.listen(3000, () => {
console.log(`Server running at http://localhost:${port}`);
});