Created
December 20, 2022 12:14
-
-
Save iamso1/79bb8a0d772f3fc45cf321ab67929aba to your computer and use it in GitHub Desktop.
cors-proxy-test
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 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