I am trying to use a custom webfont to style a Stripe CardElement component. I have configured Stripe correctly to load the font, but it is blocked by CORS.
Access to font at 'https://...com/webfonts/stripe/L10-Regular.woff2' from origin 'https://js.stripe.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
(I'm using ...com
in place of my live domain because the site is not yet ready to be public.)
In Node/Express, I have the following configuration:
app.use('/webfonts/stripe(/*)?', cors({
origin: 'https://js.stripe.com',
methods: ['GET', 'HEAD'],
allowedHeaders: ['Origin', 'X-Requested-With', 'Content-Type', 'Accept']
}))
In the webfonts/stripe
directory there is a l10-web.css
file which I am passing to Stripe, here are its contents:
@font-face {
font-family: "L10-Web";
src: url("https://...com/webfonts/stripe/L10-Regular.woff2") format("woff2"),
url("https://...com/webfonts/stripe/L10-Regular.woff") format("woff");
font-style: normal;
font-weight: 400;
}
And the two woff/2
files referenced in the CSS file.
I also tried setting each route explicitly (e.g. app.use('/webfonts/stripe/L10-Regular.woff', …)
) but that didn't work either.
Is there something obvious I'm missing here? I don't understand why it says I'm missing the Access-Control-Allow-Origin
header when I have it set in Express. I have set CORS on other routes just fine. Is it something to do with files?
(I have googled and googled and googled btw but to no avail)