-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAP
42 lines (36 loc) · 1.22 KB
/
AP
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
const express = require("express");
const fetch = require("node-fetch"); // For making HTTP requests
require("dotenv").config(); // Load environment variables
const app = express();
const PORT = process.env.PORT || 3000;
// API Configuration
const FINRA_API_URL = "https://gateway.finra.org/api/v1/market-data/reports";
const API_KEY = process.env.FINRA_API_KEY; // Secure API key with environment variable
// Route to Fetch FINRA Data
app.get("/api/finra-data", async (req, res) => {
try {
// Fetch data from FINRA API
const response = await fetch(FINRA_API_URL, {
method: "GET",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
});
// Handle response
if (!response.ok) {
return res.status(response.status).json({
error: `FINRA API Error: ${response.statusText}`,
});
}
const data = await response.json();
res.json(data); // Send the data as JSON to the client
} catch (error) {
console.error("Error fetching FINRA data:", error);
res.status(500).json({ error: "Internal Server Error" });
}
});
// Start the Server
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});