Skip to content

Instantly share code, notes, and snippets.

@omarkj
Created January 29, 2016 19:44
Show Gist options
  • Save omarkj/221f17f26acb344ca377 to your computer and use it in GitHub Desktop.
Save omarkj/221f17f26acb344ca377 to your computer and use it in GitHub Desktop.
Testing against DynamoDB local and Kinesalite
#!/usr/bin/env node
const http = require('http');
const bind = '127.0.0.1';
const port = 8081;
const port_map =
{'Kinesis': 4567, 'DynamoDB': 8000};
http.createServer((req, res) => {
var amz_target = req.headers['x-amz-target'].split('_')[0];
var proxy_req_opts = {
host: '127.0.0.1',
port: port_map[amz_target],
method: req.method,
path: req.url,
headers: req.headers
};
var p_req = http.request(proxy_req_opts, (inner_res) => {
res.writeHead(inner_res.statusCode, inner_res.headers);
inner_res.on('data', (chunk) => { res.write(chunk); });
inner_res.on('end', () => { res.end(); });
inner_res.on('error', (error) => {
console.log(`Error connecting to backend: ${error}`);
});
});
req.on('data', (chunk) => { p_req.write(chunk); });
req.on('end', () => { p_req.end(); });
}).listen(port, bind, () => {
console.log(`Proxy running at http://${bind}:${port}/`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment