我正在努力使cors-任何地方工作在我的nodejs/快递,但没有成功。
首先,我像这样使用express-cors-anywhere:
const anywhere = require('express-cors-anywhere')
app.use("/cors-anywhere", anywhere())但是,得到以下错误:
anywhere is not a function我尝试过使用本机cors-anywhere库,但我不知道如何在express js应用程序上实现这一点:
var cors_proxy = require('cors-anywhere');
cors_proxy.createServer({
originWhitelist: [], // Allow all origins
requireHeader: ['origin', 'x-requested-with'],
removeHeaders: ['cookie', 'cookie2']
}).listen(port, host, function() {
console.log('Running CORS Anywhere on ' + host + ':' + port);
});有什么建议吗?
发布于 2022-08-08 22:43:39
如何与现有的高速公路服务器#81集成
let proxy = corsAnywhere.createServer({
originWhitelist: [], // Allow all origins
requireHeaders: [], // Do not require any headers.
removeHeaders: [] // Do not remove any headers.
});
/* Attach our cors proxy to the existing API on the /proxy endpoint. */
api.get('/proxy/:proxyUrl*', (req, res) => {
req.url = req.url.replace('/proxy/', '/'); // Strip '/proxy' from the front of the URL, else the proxy won't work.
proxy.emit('request', req, res);
});https://stackoverflow.com/questions/72398564
复制相似问题