Reputation: 21
I'm working on a project using the dexFinal repository. When I run the project directly, I encounter CORS (Cross-Origin Resource Sharing) issues. Here is the error message I receive:
Access to XMLHttpRequest at 'https://api.1inch.io/v5.0/1/approve/allowance?tokenAddress=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&walletAddress=0x1d27d99AC42Acc3A50D390c63b4d4E1d5bc53fD3' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I have tried several methods to resolve this issue, including:
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/api',
createProxyMiddleware({
target: 'https://api.1inch.dev',
changeOrigin: true,
pathRewrite: {
'^/api': '',
},
headers: {
'Authorization': 'Bearer xxx',
},
})
);
};
server {
listen 80;
server_name localhost;
location /api {
proxy_pass https://api.1inch.dev;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
add_header 'Access-Control-Allow-Origin' '*';
}
}
Despite these attempts, I still face the same CORS issue. I have confirmed that my front-end application is running on http://localhost:3000 and the API I am trying to access is https://api.1inch.dev.
npm install
npm run start
npm install
node index.js
Has anyone faced similar issues and found a solution? Any help or guidance would be greatly appreciated.
Thank you!
Upvotes: 0
Views: 42