Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!DOCTYPE html>
<html>
<head>
<title>iFrame Proxy</title>
</head>
<body>
<iframe src="http://localhost:3000?domain=google.com" width="800" height="400"></iframe>
<script>
const domain = (new URL(document.location)).searchParams.get('domain')
const element = document.querySelector('iframe')
element.src = `http://localhost:3000?domain=${domain}`
</script>
</body>
</html>
const { createServer } = require('http')
const { createReadStream } = require('fs')
const request = require('request')
createServer((req, res) => {
const url = new URL(req.url, `http://${req.headers.host}`)
const domain = url.searchParams.get('domain')
if (!domain) {
return createReadStream('./index.html').pipe(res)
}
const headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
}
request({ url: `http://${domain}`, headers }, (error, response, body) => {
if (error) return res.end()
for (const [name, value] of Object.entries(response.headers)) {
if (name === 'x-frame-options') continue
res.setHeader(name, value)
}
res.end(body)
})
}).listen(3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment