Closed TilWiggers closed 4 months ago
You'll need to proxy your request to google to handle cors. For example in a Express app, you can add the necessary cors headers:
import cors from "cors";
import express from "express";
import { createProxyMiddleware } from 'http-proxy-middleware';
const app = express();
app.use(cors());
const GoogleProxy = createProxyMiddleware({
target: 'https://www.google.com', // target host with the same base path
changeOrigin: true,
autoRewrite:true,
logLevel: 'debug',
pathRewrite: {
[`^/api/google`]: '',
},
});
app.use('/api/google', GoogleProxy );
You would then change your fetch to:
fetch("https://api.MYDOMAIN.com/api/google", {
body,
method: "GET",
headers: {
"Authorization": this.token,
"Content-Type": "application/x-www-form-urlencoded"
}
})
See https://docs.stripe.com/stripe-apps/build-backend#handle-cross-origin-resource-sharing-(cors)
The proxy did the trick. Thanks!
Describe the bug I want to fetch data from an external api from a "Stripe Apps frontend component". But I get the error: "Content-Security-Policy: The page’s settings blocked the loading of a resource at https://google.com/ (“connect-src”)."
To Reproduce Steps to reproduce the behavior:
Expected behavior I expect the request not to be blocked by CORS.
Screenshots
Desktop:
Additional context I double checked by using the "isSourceInAuthorizedCSP" function to confirm that the url is authorized.
https://google.com is used as a placeholder for the actual api endpoint. The actual api states: