Last active
February 7, 2017 14:59
-
-
Save honzabrecka/44cf6a0281652ef8c06767414f5f28d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http') | |
const fs = require('fs') | |
const express = require('express') | |
const app = express() | |
app.use('/proxy', (req, res) => { | |
const headers = req.headers | |
delete headers['host'] | |
const options = { | |
host: 'www.mocky.io', | |
port: 80, | |
path: '/v2/5899dc3e0f0000890a1f4c56', | |
method: 'POST', | |
headers: headers | |
} | |
const fixture = fs.createWriteStream('./fixture', 'utf-8'); | |
const proxy = req.pipe(http.request(options, r => { | |
res.status(r.statusCode).header('Content-Type', 'application/json') | |
r.on('data', (chunk) => { | |
res.write(chunk) | |
fixture.write(chunk) | |
}) | |
r.on('end', () => { | |
res.end() | |
fixture.end() | |
console.log('end') | |
}) | |
})); | |
}) | |
app.listen(4000, () => { | |
console.log('started') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment