-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
59 lines (50 loc) · 1.72 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
const express = require("express");
const path = require("path");
const fetch = require("node-fetch");
require("dotenv").config();
const app = express();
app.use(express.static(path.join(__dirname, "client/build")));
const api_key = process.env.API_KEY;
const sb_api_key = process.env.SB_API_KEY;
app.get("/api/dailydata/:ticker/:time", async (req, res) => {
const { ticker, time } = req.params;
const fetch_response = await fetch(
`https://sandbox.iexapis.com/stable/stock/${ticker}/chart/${time}?token=${sb_api_key}`
);
const data = await fetch_response.json();
res.json(data);
});
app.get("/api/info/:ticker", async (req, res) => {
const { ticker } = req.params;
const response = await fetch(
`https://sandbox.iexapis.com/stable/stock/${ticker}/company?token=${sb_api_key}`
);
const data = await response.json();
res.json(data);
});
app.get("/api/logo/:ticker", async (req, res) => {
const { ticker } = req.params;
const response = await fetch(
`https://cloud.iexapis.com/stable/stock/${ticker}/logo?token=${api_key}`
);
const data = await response.json();
res.json(data);
});
app.get("/api/price/:ticker", async (req, res) => {
const { ticker } = req.params;
const response = await fetch(
`https://sandbox.iexapis.com/stable/stock/${ticker}/price?token=${sb_api_key}`
);
const data = await response.json();
res.json(data);
});
app.get("/api/news/:ticker", async (req, res) => {
const { ticker } = req.params;
const response = await fetch(
`https://cloud.iexapis.com/stable/stock/${ticker}/news/last/3?token=${api_key}`
);
const data = await response.json();
res.json(data);
});
const port = process.env.PORT || 5000;
app.listen(port, () => `Server running on port ${port}`);