gatsby-source-strapi
gatsby-source-strapi copied to clipboard
Need a customize headers option pass to gatsby-source-filesystem plugin
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:
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