Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR creates a route to retrieve the
netlify.toml
file from the site's repo via the Github API and parse it to return its header values. This route is useful on the frontend because we are using the CSP rules specified in the header values to sanitise the page preview when users edit pages (link).An example of the headers retrieved in the
netlify.toml
file:An example of the response sent to the frontend:
A new
NetlifyToml
class was created because Isomer has a future goal to make thenetlify.toml
file a centralized setting across all sites, so we wouldn't need the other methods of theFile
class :create
,update
,delete
. By creating a separate file, this allows us to maintain/ remove this functionality easily in the future.Note that we use the simplifying assumption that only one set of header values are specified and applied to all paths under each site. This is currently true for all Isomer repos, where
[[headers]]
is an array of length one, andfor = "/*"
which indicates that all paths on the site are affected by the corresponding set of[header.values]
.