Data Bento Proxy
Overview
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;
const test = false;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
//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) =>{
debugger;
// Destructure following properties from request object
const { method, url, headers, body } = req;
const server = 'https://hist.databento.com'
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:{'authorization':headers['authorization']},
data: body
});
//console.log('response - '+response.data)
//res.set('Content-Type', 'text/plain');
//res.send('hello');
// Send back the response data
// from application server 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());
});
*/