Skip to content

Instantly share code, notes, and snippets.

@bodokaiser
Created May 21, 2021 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bodokaiser/3dcc8d70261e1a37a7f185281700c1a3 to your computer and use it in GitHub Desktop.
Save bodokaiser/3dcc8d70261e1a37a7f185281700c1a3 to your computer and use it in GitHub Desktop.
<!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