Created
May 21, 2021 12:48
-
-
Save bodokaiser/3dcc8d70261e1a37a7f185281700c1a3 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
<!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> |
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 { 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