-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (34 loc) · 1.04 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
// res.write(`<script>console.log("response}");</script>`);
const express = require("express");
const fs = require("fs");
const axios = require("axios");
const app = express();
let resp;
let response;
const fun = async () => {
try {
response = await axios.get("http://localhost:5000/"); // Assuming Python server runs on port 5000
resp = response.data;
console.log(resp.name);
} catch (error) {
console.error(error);
res.status(500).send("Error fetching data from Python");
}
};
fun();
app.use("/", express.static(__dirname + "/"));
// Route to fetch data from Python
app.get("/", async (req, res) => {
fs.readFile("src/index.html", async (err, data) => {
res.writeHead(200, { "Content-Type": "text/html" });
response = await axios.get("http://localhost:5000/"); // Assuming Python server runs on port 5000
res.write(response.data.name);
return res.end(data);
});
});
// Other routes and middleware
// ...
const port = 3030;
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});