-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
116 lines (97 loc) · 2.7 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
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
112
113
114
115
116
import 'dotenv/config';
import express from 'express';
import request from 'request';
import axios from 'axios';
import cors from 'cors';
const app = express()
const port = process.env.PORT || 3000
app.use(cors(
{
origin: process.env.ORIGIN,
credentials: true
}
));
app.use((req, res, next) => {
console.log(req.headers);
next();
})
app.get("/", (req, res) => {
res.send("Hello World!");
});
app.get('/check-symbol', async (req, res) => {
const targetUrl = `${process.env.API_BASE_URL}/search?q=AAPl&token=${process.env.API_KEY}`
try {
axios.get(`${targetUrl}`)
.then(response => res.send(response.data))
.then(response => console.log(response.data))
.catch(error => res.send(error));
} catch (error) {
console.log(error)
}
})
app.get('/quote-default-stocks', async (req, res) => {
try {
axios.get(`${process.env.API_BASE_URL}/quote?symbol=AAPL&token=${process.env.API_KEY}`)
.then(response => res.send(response.data))
.then(response => console.log(response.data))
.catch(error => res.send(error));
} catch (error) {
console.log(error)
}
})
app.get('/news', async (req, res) => {
try {
axios.get(`${process.env.API_BASE_URL}/company-news?symbol=AAPL&from=2022-12-20&to=2022-12-30&token=${process.env.API_KEY}`)
.then(response => res.send(response.data))
.then(response => console.log(response.req.query.symbol))
.catch(error => res.send(error));
} catch (error) {
console.log(error)
}
})
app.get("/:anyPath", (req, res) => {
console.log(req.url)
const targetUrl = process.env.TARGET +"/"+ req.url;
request(targetUrl).pipe(res);
});
app.listen(port)
/*
const express = require('express');
const axios = require('axios');
const app = express();
const API_KEY = 'your_api_key';
const API_BASE_URL = 'https://finnhub.io/api/v1';
app.get('/news', (req, res) => {
axios.get(`${API_BASE_URL}/news`, {
params: {
token: API_KEY,
symbol: req.query.symbol
}
})
.then(response => res.send(response.data))
.catch(error => res.send(error));
});
app.get('/quote', (req, res) => {
axios.get(`${API_BASE_URL}/quote`, {
params: {
token: API_KEY,
symbol: req.query.symbol
}
})
.then(response => res.send(response.data))
.catch(error => res.send(error));
});
app.get('/symbol', (req, res) => {
axios.get(`${API_BASE_URL}/stock/symbol`, {
params: {
token: API_KEY,
exchange: req.query.exchange
}
})
.then(response => res.send(response.data))
.catch(error => res.send(error));
});
app.listen(3000, () => {
console.log('Reverse proxy listening on port 3000');
});
*/