Skip to content

feat(netlify): add experimental support for static headers#13952

Merged
ematipico merged 10 commits intomainfrom
feat/csp-netlify
Jun 16, 2025
Merged

feat(netlify): add experimental support for static headers#13952
ematipico merged 10 commits intomainfrom
feat/csp-netlify

Conversation

@ematipico
Copy link
Copy Markdown
Member

Changes

This PR adds support for static headers for the Netlify adapter. The initial implementation supports the experimental CSP feature. In the future, this may change, and we will update the documentation as needed.

@astrojs/underscore-redirects

To implement the feature, I had to make some breaking changes within underscore-redirects. The package is mostly for internal usage, so we don't have strong documentation and it's mostly for our needs, so the changesets are mostly technical.

The functionality for redirects must stay the same.

The printing logic has been removed from Redirects, instead consumers need to use printAsRedirects instead. The core functionality hasn't changed much, it now accounts for .target, because it's now optional.

@astrojs/netlify

The function that creates config.json is now called in the astro:build:done hook, because we need to collect the static headers from the hook astro:build:generated.

The new logic now loops through the new static headers, and if cps is enabled, they are added to the final config.json.

Testing

Added a new test. Existing tests should still pass.

Docs

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 16, 2025

🦋 Changeset detected

Latest commit: 088b2ae

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the pkg: integration Related to any renderer integration (scope) label Jun 16, 2025
Comment thread packages/integrations/netlify/src/index.ts
Comment thread packages/integrations/netlify/src/index.ts Outdated
Copy link
Copy Markdown
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two tiny nits!

Comment thread .changeset/sweet-hotels-cross.md Outdated
Comment thread .changeset/sweet-hotels-cross.md Outdated
Comment thread .changeset/sweet-hotels-cross.md Outdated
Comment thread packages/integrations/netlify/src/index.ts Outdated
@ematipico ematipico requested review from ascorbic and sarah11918 June 16, 2025 12:16
Copy link
Copy Markdown
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a deal breaker, but since this is something a user would enable for the Netlify adapter, it might help to make this one changeset more user-focused (so they know what effect enabling this would have on their project, and why they might want to do it).

Nothing wrong with the original one if that's the only info you want to provide! But I don't think the explanation connects all the dots for them that it could. So, suggestion below (but make it accurate).

Comment thread .changeset/sweet-hotels-cross.md Outdated
Copy link
Copy Markdown
Contributor

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the changeset, this looks good

@ematipico ematipico self-assigned this Jun 16, 2025
@ematipico ematipico requested a review from sarah11918 June 16, 2025 14:01
Copy link
Copy Markdown
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@github-actions github-actions Bot added the pkg: astro Related to the core `astro` package (scope) label Jun 16, 2025
@ematipico ematipico merged commit de82ef2 into main Jun 16, 2025
5 checks passed
@ematipico ematipico deleted the feat/csp-netlify branch June 16, 2025 16:15
@astrobot-houston astrobot-houston mentioned this pull request Jun 16, 2025
openscript pushed a commit to openscript/astro that referenced this pull request Sep 12, 2025
…#13952)

Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>


Co-authored-by: ascorbic <213306+ascorbic@users.noreply.github.com>
Co-authored-by: sarah11918 <5098874+sarah11918@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants