Handle custom metadata dinamically
See original GitHub issueIs there any way to handle custom “headers” as metadata when uploading files to S3?
I know the existence of params
in plugin’s config, the issue is that it accepts a plain object. I’m looking for a dynamically way to inject such configuration after SSR.
My use case is for each html file attach a Content-Security-Policy
header that can then be served from S3. Each file is set a header during SSR by using gatsby-plugin-csp
which I intercept and write in ./cache/s3.metadata.json
file and skip the html meta tag.
Then, during deployment I would like to retrieve that data and merge with s3.params.json
.
I’ve successfully hacked /src/bin.ts#L245 to receive an additional s3.metadata.json
file with Metadata
objects.
If you think this is not supported, would you see it feasible to implement one of the following solutions:
- somehow pass a function to
params
in config that would run during deployment (not ideal I believe) - during
s3.params.json
generation merge that info somehow (by passing a newadditionalParamsFile
optional plugin option).
Thank you.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:14 (3 by maintainers)
Hi! You’re not incorrect, but while it is not possible to append data without
x-amz-meta-
prefix, you can use Cloudfront Lambda Edge, as you mentioned, to parse those keys (if present) and return the correct HTTP headers based on a white list.In my case, that’s exactly what I’m doing. I have .html files with
x-amz-meta-content-security-policy
metadata. The lambda “copies” the content and creates aContent-Security-Policy
header with that value.Well, the problem, as you might realise, is that the params are serialised to JSON once the actual deployment phase is running.
We could (before writing the params into
s3.params.json
) check if any of the values in the params object are of a function type, execute said function, and then serialize the result into the file.Would that suffice for your use case @lightningspirit? I don’t have the time right now to figure out how the mentioned CSP plugin works.