Added webpage

This commit is contained in:
Marcus Noble 2021-03-21 10:11:10 +00:00
parent e514f3088b
commit 37ee6a3091
4 changed files with 119 additions and 4 deletions

View File

@ -4,6 +4,6 @@ WORKDIR /app
ADD package.json .
RUN npm install
ADD index.js .
ADD index.js index.html ./
CMD npm start

View File

@ -1,5 +1,6 @@
# CorsProxy
Super simple CORS proxy supporting most (maybe all?) HTTP verbs.
![CorsProxy](logo.png)
> A proxy enabling CORS headers on responses, supporting most (maybe all?) HTTP verbs.
# Usage
@ -7,6 +8,6 @@ Super simple CORS proxy supporting most (maybe all?) HTTP verbs.
1. `node index.js`
1. Navigate to `http://localhost:8000/http://www.example.com`
To change the listening port either set the `PORT` environment variable to pass it in as an argument.
To change the listening port either set the `PORT` environment variable to pass it in as an argument.
E.g. `node index.js --port=8080`

95
index.html Normal file
View File

@ -0,0 +1,95 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CorsProxy</title>
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 512 512' fill='%23ef71a8'%3E%3Cg%3E%3Cg%3E%3Cpath d='M132.7 108A132.9 132.9 0 000 240.9c0 34.9 16.3 85.9 41.6 129.8 28.7 50 62 78.8 91.1 78.8 29.2 0 62.5-28.7 91.2-78.8 25.3-44 41.6-94.9 41.6-129.8 0-73.2-59.6-132.7-132.8-132.7zm0 322.4C91.5 430.4 19 320.8 19 240.8A114 114 0 01132.7 127a114 114 0 01113.8 113.8c0 80-72.6 189.6-113.8 189.6z'/%3E%3C/g%3E%3C/g%3E%3Cg%3E%3Cg%3E%3Cpath d='M132.7 174.4a66.4 66.4 0 10.2 133 66.4 66.4 0 00-.2-133zm0 113.8a47.5 47.5 0 11.2-95 47.5 47.5 0 01-.2 95z'/%3E%3C/g%3E%3C/g%3E%3Cg%3E%3Cg%3E%3Cpath d='M417.2 13.2a95 95 0 00-94.8 94.9c0 47.7 57.6 142.2 94.8 142.2S512 155.8 512 108a95 95 0 00-94.8-94.9zm0 218.1c-20 0-75.9-77.8-75.9-123.2a76 76 0 01151.7 0c0 45.4-56 123.2-75.8 123.2z'/%3E%3C/g%3E%3C/g%3E%3Cg%3E%3Cg%3E%3Cpath d='M417.2 60.7a47.5 47.5 0 10.1 94.9 47.5 47.5 0 00-.1-95zm0 75.8a28.5 28.5 0 110-57 28.5 28.5 0 010 57z'/%3E%3C/g%3E%3C/g%3E%3Cg%3E%3Cg%3E%3Cpath d='M347.4 366.3c-11.4-9.6-16.7-19.6-16-30.7 1.2-24.8 32-50.6 43.6-58.5a9.5 9.5 0 00-10.5-15.7c-2 1.3-50 33.8-52.1 73.1-1 17.3 6.7 32.9 22.9 46.3 35.1 29.3 54.6 59 49.6 75.6-4.2 14.1-26.6 19.5-44.6 21.5-81.6 9-146.3-18-147-18.3a9.5 9.5 0 10-7.4 17.5c2.4 1 51.5 21.7 119.9 21.7 11.7 0 24-.6 36.6-2 34.5-3.9 54.9-15.6 60.7-35 10.3-34.2-30.5-74.5-55.7-95.5z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A">
<meta property="og:title" content="CorsProxy">
<meta property="og:site_name" content="CorsProxy">
<meta property="og:url" content="https://cors-proxy.cluster.fun">
<meta property="og:description" content="A proxy enabling CORS headers on responses, supporting most (maybe all?) HTTP verbs">
<meta property="og:type" content="website">
<meta property="og:image" content="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSItNTAwIC0xMDAgMTUxMiA3MTIiIGZpbGw9IiNlZjcxYTgiPgogIDxnPgogICAgPGc+CiAgICAgIDxwYXRoIGQ9Ik0xMzIuNyAxMDhBMT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AwIDAxMCA1N3oiLz4KICAgIDwvZz4KICA8L2c+CiAgPGc+CiAgICA8Zz4KICAgICAgPHBhdGggZD0iTTM0Ny40IDM2Ni4zYy0xMS40LTkuNi0xNi43LTE5LjYtMTYtMzAuNyAxLjItMjQuOCAzMi01MC42IDQzLjYtNTguNWE5LjUgOS41IDAgMDAtMTAuNS0xNS43Yy0yIDEuMy01MCAzMy44LTUyLjEgNzMuMS0xIDE3LjMgNi43IDMyLjkgMjIuOSA0Ni4zIDM1LjEgMjkuMyA1NC42IDU5IDQ5LjYgNzUuNi00LjIgMTQuMS0yNi42IDE5LjUtNDQuNiAyMS41LTgxLjYgOS0xNDYuMy0xOC0xNDctMTguM2E5LjUgOS41IDAgMTAtNy40IDE3LjVjMi40IDEgNTEuNSAyMS43IDExOS45IDIxLjcgMTEuNyAwIDI0LS42IDM2LjYtMiAzNC41LTMuOSA1NC45LTE1LjYgNjAuNy0zNSAxMC4zLTM0LjItMzAuNS03NC41LTU1LjctOTUuNXoiLz4KICAgIDwvZz4KICA8L2c+Cjwvc3ZnPgo=">
<meta name="twitter:card" content="summary" />
<meta name="twitter:creator" content="@Marcus_Noble_" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.css">
<link rel="stylesheet" href="https://githubraw.com/AverageMarcus/milligram/master/dist/milligram.min.css">
<style>
body {
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
img {
max-width: 100%;
}
textarea {
height: 200px;
}
</style>
</head>
<body>
<div class="container">
<h1 class="heading-fancy">
CorsProxy
<svg style="height:50px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 512 512" fill="#ef71a8"><g><g><path d="M132.7 108A132.9 132.9 0 000 240.9c0 34.9 16.3 85.9 41.6 129.8 28.7 50 62 78.8 91.1 78.8 29.2 0 62.5-28.7 91.2-78.8 25.3-44 41.6-94.9 41.6-129.8 0-73.2-59.6-132.7-132.8-132.7zm0 322.4C91.5 430.4 19 320.8 19 240.8A114 114 0 01132.7 127a114 114 0 01113.8 113.8c0 80-72.6 189.6-113.8 189.6z"/></g></g><g><g><path d="M132.7 174.4a66.4 66.4 0 10.2 133 66.4 66.4 0 00-.2-133zm0 113.8a47.5 47.5 0 11.2-95 47.5 47.5 0 01-.2 95z"/></g></g><g><g><path d="M417.2 13.2a95 95 0 00-94.8 94.9c0 47.7 57.6 142.2 94.8 142.2S512 155.8 512 108a95 95 0 00-94.8-94.9zm0 218.1c-20 0-75.9-77.8-75.9-123.2a76 76 0 01151.7 0c0 45.4-56 123.2-75.8 123.2z"/></g></g><g><g><path d="M417.2 60.7a47.5 47.5 0 10.1 94.9 47.5 47.5 0 00-.1-95zm0 75.8a28.5 28.5 0 110-57 28.5 28.5 0 010 57z"/></g></g><g><g><path d="M347.4 366.3c-11.4-9.6-16.7-19.6-16-30.7 1.2-24.8 32-50.6 43.6-58.5a9.5 9.5 0 00-10.5-15.7c-2 1.3-50 33.8-52.1 73.1-1 17.3 6.7 32.9 22.9 46.3 35.1 29.3 54.6 59 49.6 75.6-4.2 14.1-26.6 19.5-44.6 21.5-81.6 9-146.3-18-147-18.3a9.5 9.5 0 10-7.4 17.5c2.4 1 51.5 21.7 119.9 21.7 11.7 0 24-.6 36.6-2 34.5-3.9 54.9-15.6 60.7-35 10.3-34.2-30.5-74.5-55.7-95.5z"/></g></g></svg>
</h1>
<blockquote>
A proxy enabling CORS headers on responses, supporting most (maybe all?) HTTP verbs.
</blockquote>
<p>
Enter the URL you would like to proxy to and press the "Proxy" button
</p>
<div class="row">
<form id="proxyForm" class="column column-80 column-offset-10" method="GET" action="/">
<fieldset>
<label for="url">URL</label>
<input type="text" placeholder="e.g. https://marcusnoble.co.uk" name="url" id="url">
<input id="proxy" class="button-primary button-outline float-right" type="submit" value="Proxy">
</fieldset>
</form>
</div>
<div class="row">
<div id="results" class="column column-80 column-offset-10 text-center"></div>
</div>
<hr>
<div>
Source code available on <a href="https://github.com/AverageMarcus/cors-proxy" target="_blank" rel="noopener noreferrer">GitHub</a>, <a href="https://gitlab.com/AverageMarcus/cors-proxy" target="_blank" rel="noopener noreferrer">GitLab</a>, <a href="https://bitbucket.org/AverageMarcus/cors-proxy/" target="_blank" rel="noopener noreferrer">Bitbucket</a> & <a href="https://git.cluster.fun/AverageMarcus/cors-proxy" target="_blank" rel="noopener noreferrer">my own Gitea server</a>.
</div>
</div>
<div class="container">
<div class="row">
<div class="column column-60 column-offset-20">
<footer>
Made with
<svg height="20" class="fill-primary" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 449.3 449.3" xmlns:xlink="http://www.w3.org/1999/xlink"><title>love</title><g><path d="M0 162.7c1.5-7.7 2.7-15.4 4.5-23A125.5 125.5 0 0132 88a136.3 136.3 0 0162.7-40.6c8.3-2.9 17.7-3.2 26.6-3.7a134 134 0 0155.6 6.6c14.9 5.7 30 11 41 23.6 17-20 36.4-36.3 60-46.4 12-5.2 25.7-6.9 38.7-9.4a79.4 79.4 0 0140.3 3.2 96.4 96.4 0 0143.2 26 209.8 209.8 0 0137.8 55.4 133.2 133.2 0 0111 65.7c-3.2 42.2-21 79-41.5 114.8a431.2 431.2 0 01-47.6 64.3c-19.6 23-39.7 45.7-59.6 68.5-3.7 4.3-7.2 9-11.7 12.4-7.3 5.4-15.9 4.9-23.8 1.5-21.9-9.2-43.8-18.5-65.3-28.5a520.1 520.1 0 01-98-58.7c-28.2-21.5-55.5-44.3-74-75.3a183.8 183.8 0 01-25-61.4c-1-6.2-1.6-12.6-2.4-18.8v-24.5zM138 281l2.5.1c0 2.1.3 4.3 0 6.3l-9 55.5c-.3 1.6 0 4.2 1 5 5.8 4.1 11.8 7.8 17.9 11.8l11-59.7 2.5.3c3.7 21.6-6.3 42-7.6 63.5l19.4 9.6c.5-18 2.2-35 6.9-51.6 1.3 4 1.5 8 1.2 12-.7 11.2-1 22.5-2.6 33.7-1 7.3 1.9 10.6 8 13.3 27 11.7 54.1 23.5 81 35.7 5.5 2.5 8.8 1.5 12.6-2.9 12.5-14.4 25.7-28.1 38-42.7 17.2-20.2 34.5-40.5 50.5-61.7 29.5-39.2 52.7-81.7 61-131 3.6-21.7 2-43-5.6-63.5a176 176 0 00-33.9-54.5 84.8 84.8 0 00-38-26 91.2 91.2 0 00-44.2-2.5c-13 2-25.6 5.1-37.2 12.3a208.6 208.6 0 00-45.9 37c-5.7 6.3-7.8 6.4-15 1.4-5.7-4-11-8.8-17.2-11.9-15.1-7.5-30.7-14.4-48-14.9-13.7-.4-28-2-41.2 1-36 8.4-62.7 30-80.3 62.8a111 111 0 00-11.7 56.6c.3 10 1.4 20 2.2 29.9 7-18.9 11-38.3 19.7-56.3.6 3 .6 6 0 8.7l-14.5 53.2c-.7 2.6-2 5.7-1.2 8 2.7 8.4 6.2 16.6 9.4 24.8 0-20 13.7-63.9 21.8-66.8 0 .6.3 1.1.2 1.6a11936 11936 0 01-17 64c-.3 1.4-1.6 2.6-2.9 4.5l9.7 17a573 573 0 0120-67.3l2.9.7c-1 5-1.5 10-2.8 14.9-4.7 17.2-9.6 34.3-14.2 51.5-.7 2.5-1.5 6-.3 7.8 3.6 5.6 8 10.7 12.4 16.1 1.8-8.6 3.1-16.6 5.2-24.4 3.1-11.5 6.6-22.9 10.2-34.3.8-2.6 2.7-5 4-7.4l2 .8c-.1 1.6-.1 3.4-.5 5l-12.2 47.4c-4.6 17.9-4.3 18.9 7.8 29.4 2.2 1.8 4.5 3.5 7 5.3 3.7-31 12.5-64.7 18.4-68-.3 3.5-.3 6.6-.9 9.6l-12.7 58.8c-.3 1.2-.7 3-.1 3.5 4.7 4.4 9.6 8.6 14.5 12.9 3.5-21.4 7.6-41.7 13.6-61.6 3.4 8.7.6 17-.8 25.2-1.9 11.6-4.5 23.1-6.5 34.7-.4 2.3-.4 6 1 7 4.8 4.2 10.3 7.4 16 11.3 3.9-21.5 5.5-42.6 12.6-62.5z"/><path d="M323.2 180.5a24 24 0 01-24.5-19.7c-2-9.7.7-20.2 15-27 16.6-7.8 38.3 2.3 41.6 19.5 1.2 6.6-1.6 12.1-6 16.3a35.1 35.1 0 01-26 11z"/><path d="M138.9 167.1a31 31 0 0125 12.7 22 22 0 01-13.6 34.9 29.9 29.9 0 01-31-9.9c-6-7-7.6-15.3-4.1-24.1 3.7-9.5 12-12 21-13.5.8-.2 1.8 0 2.7 0z"/><path d="M233.2 202c-18.5-.4-33.7-13.6-34-29.7 0-4.2.4-8 5.4-8.7 4.5-.7 6.6 2.3 8 6 2.3 6.6 5.5 12.4 12.4 15.4 7.5 3.2 14 1.5 20.4-3.3 6.2-4.7 6.4-11 4.7-17.5-1.4-5.2.4-8.4 4.7-10.2 4.3-1.7 9 1.3 10.9 6.2 7.2 19.8-5.7 34.6-22.8 40.2-3 1-6.5 1-9.7 1.6z"/><path d="M201.2 384.7c-.9-2-2.7-4.2-2.5-6.2 1.2-14 2.8-28.1 4.4-42.2 0-.9.7-1.7 1-2.6l2.6 1.1-3.1 49.1-2.4.8z"/><path d="M222 387.4c-4.8-5.7-5-15-1-37.8 3.1 3 4 30.5 1 37.8z"/><path d="M240.9 361.7l-1.4 20.2c-4.8-3.3-4.6-11.9-.2-20.4l1.6.2z"/><path d="M257.4 380.4c-4.1-5.2-3.7-9.7 1-14.7l-1 14.7z"/></g></svg>
by <a href="https://marcusnoble.co.uk" class="fancy-link">Marcus Noble</a>
</footer>
</div>
</div>
</div>
<script>
document.getElementById('proxyForm').addEventListener('submit', function(e) {
let proxyURL = e.target.action + document.getElementById('url').value;
document.getElementById('results').innerHTML = `<h3 class="heading-fancy">Proxied URL</h3><br><a href="${proxyURL}" target="_blank" rel="noopener noreferrer">${proxyURL}</a><br><br>`
e.preventDefault();
});
</script>
</body>
</html>

View File

@ -2,6 +2,7 @@
const request = require('request');
const http = require('http');
const url = require('url');
const fs = require('fs').promises;
let PORT = process.env.PORT || 8000;
process.argv.forEach(function (arg) {
@ -11,6 +12,10 @@ process.argv.forEach(function (arg) {
});
http.createServer((req, response) => {
if (!req.url.substring(1)) {
return loadWebpage(req, response);
}
let remoteURL = url.parse(req.url.substring(1));
if(!remoteURL.hostname || remoteURL.hostname === 'localhost') return response.end();
@ -58,3 +63,17 @@ http.createServer((req, response) => {
.on('end', () => response.end());
}).listen(PORT);
function loadWebpage(req, res) {
fs.readFile(__dirname + "/index.html")
.then(contents => {
res.setHeader("Content-Type", "text/html");
res.writeHead(200);
res.end(contents);
})
.catch(err => {
res.writeHead(500);
res.end(err);
return;
});
}