gatsby-source-strapi icon indicating copy to clipboard operation
gatsby-source-strapi copied to clipboard

Need a customize headers option pass to gatsby-source-filesystem plugin

Open whidy opened this issue 2 years ago • 0 comments

Before this v4 plugin published, I use another plugin relate-app/gatsby-source-strapi for replaced. That plugin document has provide options but not passing headers, I don't know why.

But add a additional headers it really useful. Sometimes markdown content has a CDN image with security policy cannot visit directly, we need send customize headers for gatsby node request. Or it will throw an error as:

image

I can temporary fix it through edit my local node_modules files, but not a good way if I install depencies package next time. So I think it it necessary to be added.

I change my local files temporary:

// gatsby-config.js
const strapiConfig = {
  apiURL: process.env.STRAPI_API_URL,
  accessToken: process.env.STRAPI_TOKEN,
  collectionTypes: [`post`, `category`, `tag`, `page`],
  singleTypes: [],
  headers: {
    Referer: 'https://www.whidy.net/'
  }
};

and node_modules/gatsby-source-strapi/lib/download-media-files.js which is near https://github.com/strapi/gatsby-source-strapi/blob/74e9f5c0e38149e4c3c144449312343c1ae4a565/src/download-media-files.js#L77

      const fileNode = await (0, _gatsbySourceFilesystem.createRemoteFileNode)({
        url: source_url,
        store,
        cache,
        createNode,
        createNodeId,
        httpHeaders: strapiConfig.headers
      });

after that, file will be get and save to .cache/caches/gatsby-source-strapi folder fine.

relate issue: headers Option not working

whidy avatar Feb 28 '22 07:02 whidy