Problem/Motivation

When running Storybook locally (http://localhost:6006), CORS policy errors occur for both .woff and .woff2 font files, even though the recommended cors.config has been added as described on the module's homepage.

Error message example:
Access to font at '<font-path>.woff2' from origin 'http://localhost:6006' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

These CORS errors do not appear when accessing the same fonts on the Drupal site itself.

Comments

dekisha created an issue.

marcus.w’s picture

Did you find a fix for this, I'm seeing the same issue?

sanduhrs’s picture

Apparently storybook can't return the fonts, unless you declare a static assets folder containing the files.
https://storybook.js.org/docs/configure/integration/images-and-assets

.storybook/main.js
const config = {
  [...]
  staticDirs: ["../web"],
  [...]
};
marcus.w’s picture

Turned out to be an nginx issue and I'm using valet rather than ddev. This is what got it working

    location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
        add_header Access-Control-Allow-Origin *;
        try_files /path-to-site/drupal/web$uri /path-to-site/drupal$uri =404;
        expires max;
        log_not_found off;
    }