Skip to content

Instantly share code, notes, and snippets.

@iamso1
Created December 20, 2022 12:14
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 iamso1/79bb8a0d772f3fc45cf321ab67929aba to your computer and use it in GitHub Desktop.
Save iamso1/79bb8a0d772f3fc45cf321ab67929aba to your computer and use it in GitHub Desktop.
cors-proxy-test
const express = require('express');
const http = require('http');
const cors = require('cors');
// Configure & Run the http server
const app = express();
app.use(express.static(__dirname, { dotfiles: 'allow' }));
app.use(cors());
app.get(`/`, (req, res) => {
console.log('in', req.url);
res.send('hello');
});
const cors_proxy = require('cors-anywhere');
const proxy = cors_proxy.createServer({
originWhitelist: [], // Allow all origins
requireHeader: ['origin', 'x-requested-with'],
removeHeaders: ['cookie', 'cookie2'],
});
app.all('/proxy/:data*', function (req, res) {
console.log('in proxy', req.url);
req.url = req.url.replace('/proxy/', '/'); // Strip "/proxy" from the front of the URL.
proxy.emit('request', req, res);
});
cors_proxy
.createServer({
originWhitelist: [], // Allow all origins
requireHeader: ['origin', 'x-requested-with'],
removeHeaders: ['cookie', 'cookie2'],
})
.listen(8080, '0.0.0.0', function () {
console.log('Running CORS Anywhere on 0.0.0.0:8080 ');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment