-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (42 loc) · 1.36 KB
/
Copy pathindex.js
File metadata and controls
49 lines (42 loc) · 1.36 KB
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
import express from "express";
import axios from "axios";
import bodyParser from "body-parser";
const app = express();
const port = 3000;
const API_URL = "https://api.blockchain.com/v3/exchange"
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: true }));
const totalSyms = [];
var allSyms = await axios.get(API_URL+"/symbols");
for (var key in allSyms.data){
totalSyms.push(key);
}
app.get("/", async (req, res) => {
res.render("index.ejs", {allNames: totalSyms});
});
app.post("/submit", async (req, res)=>{
var userInput = req.body["symbolName"];
if (totalSyms.includes(userInput) === true){
try {
var response = await axios.get(API_URL+"/tickers/"+userInput);
var symbo = response.data.symbol;
var price_24 = response.data.price_24h;
var vol_24 = response.data.volume_24h;
var lastTradePrice = response.data.last_trade_price;
res.render("submit.ejs", {
symbol: symbo,
price: price_24,
volume: vol_24,
lastPrice: lastTradePrice,
});
} catch (error) {
console.error("Failed to make request:", error.message);
res.render("submit.ejs", { error: error.message });
}
}else{
res.redirect("/");
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});