Fred Proxy

Overview

The fred proxy is a proxy based on the generic proxy server (see Proxies) where the server that traffic is directed to is set to point to the St Louis Federal Reserver web server

const server = 'https://api.stlouisfed.org'

Sample Proxy

const express = require('express') const bodyParser = require('body-parser') const https = require('https'); const fs = require('fs'); const path = require('path'); const app = express() const port = 443; //you need cors, otherwise davinc will report an error const cors = require('cors'); app.use(cors()); const axios = require('axios'); // Receive new request // Forward to application server const handler = async (req, res) =>{ // Destructure following properties from request object const { method, url, headers, body } = req; const server = 'https://api.stlouisfed.org' try{ let instance = axios.create({ httpsAgent: new https.Agent({ rejectUnauthorized: false }) }); // Requesting to underlying application server //console.log('call to '+`${server}${url}`) const response = await instance({ url: `${server}${url}`, method: method, //headers: headers, //headers:{}, data: body }); // Send back the response data to client res.send(JSON.stringify(response.data)); } catch(err){ // Send back the error message console.log('error - '+err.toString()) res.status(500).send("Server error!") } } // When receive new request // Pass it to handler method app.use((req,res)=>{handler(req, res)}); app.listen(port, () => { console.log(`listening on port `+port.toString()); }); /* let sslServer = https.createServer({ key: fs.readFileSync(path.join(__dirname, 'cert', 'ssl.key')), cert: fs.readFileSync(path.join(__dirname, 'cert', 'ssl.crt')) }, app); sslServer.listen(port, () => { console.log(`listening on port `+port.toString()); }); */