Hosted plans, fonts, CDN, and CORS headers


(Mark Zegarelli) #1

Hi.

I’m trying to customize the styling of our new forum, and I want to use some custom fonts. We purchased a business hosting plan directly from Discourse.

I’ve uploaded the font files to the Staff > Assets… topic, and tried several versions of the source URL. Some return 404, and others show this error in the console:

Font from origin 'https://cdn.discourse.org' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://<forum-url>.com' is therefore not allowed access. The response had HTTP status code 404.

I’ve seen similar issues in other topics where the fix was to install the header on the CDN, but the CDN in this case is Discourse’s.

Is there a recommended way to use custom fonts on a Discourse-hosted installation?

Thanks

Edit

The CORS setting in Security does not seem to work.


(Sam Saffron) #2

This is a bit of a pickle for us to sort out, cache control is set to private on uploads something that makes this less than ideal. The CORS setting is about json calls not uploads.

To work around for now I just amended your stylesheet to hit us direct, not via a CDN but clearly it is not a great long term solution, especially with cache control private.

Having a think about this issue, we may inject magical header for all uploads in the “site assets” topic … It seems like it could be the best approach

@zogstrip what are your thoughts here, there is no way to flag an upload at the moment as a “public asset”


(Mark Zegarelli) #3

Thanks a bunch @sam. I’ll keep an eye out here for any updates.

I just enabled our style and it works now.


(Justin I. Nevill) #4

Any update to this? We’re also looking for a way to include custom fonts on our hosted site and are encountering the same CORS issue with the Discourse CDN. What’s the stylesheet workaround that was mentioned? Thanks.


(Sam Saffron) #5

In your case it would be

https://cdn.discourse.org/docker :arrow_right: https://forums.docker.com for the font url.


(Justin I. Nevill) #6

Replacing the CDN URL with the site url in the font src as you suggested worked, thanks!