-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(gatsby-plugin-fastify): add customizable headers with sensible defaults for security #392
Closed
Closed
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
74b9009
add initial work from PR #98
tsdexter f82a85f
work on headers for static files
tsdexter 8053ccf
add custom headers via options config
tsdexter f50252f
fix static test
tsdexter 21b785f
Update yarn.lock
tsdexter 4797817
add changeset
tsdexter 4099220
add headers documentation
tsdexter 41ceb84
undo husky change
tsdexter 2e99ba7
add SSR specifics to documentation
tsdexter 3e84682
Update .all-contributorsrc
tsdexter 233b2ae
manually run lint-staged scripts
tsdexter dfe706f
fix linting issues
tsdexter 568e8ad
fix validate types issues
tsdexter 70e5443
refactor into headers plugin with hooks/decorators
tsdexter f91a536
Update packages/gatsby-plugin-fastify/README.md
tsdexter 67e1817
refactor array reduce to for loop
tsdexter f0fbeb5
Merge branch 'feat/fastify/default-custom-headers' of https://github.…
tsdexter 63ea4bb
Update packages/gatsby-plugin-fastify/README.md
tsdexter 1f016a7
fix dependency regression
tsdexter 42005d2
update dependencies
tsdexter 0b31e91
inline superfluous constants
tsdexter 9fcd9b1
refactor decorators, configurations to more suitable places
tsdexter 8fe0bc0
add capability to unset previously configured headers
tsdexter 9a328fb
add support for functions on gatsby hosting to test site
tsdexter 0883b8f
use `@fastify/reply-from` to serve non-wildcard rev proxy redirects
tsdexter abd1fe5
minor tweaks to get benchmarks running
tsdexter 897e7d5
refactor to build pages->headers map during `onPostBuild`
tsdexter 9bb9be1
Update packages/gatsby-plugin-fastify/README.md
tsdexter 266d421
Update packages/gatsby-plugin-fastify/README.md
tsdexter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"gatsby-plugin-fastify": minor | ||
--- | ||
|
||
Added to `options.features.headers` for configuring `customHeaders`, `useDefaultCaching`, and `useDefaultSecurity`. Please see the [Headers section](https://github.com/gatsby-uc/plugins/blob/main/packages/gatsby-plugin-fastify/README.md#headers) in the docs for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"benchmark": "node benchmark.js", | ||
"develop": "gatsby develop", | ||
"start": "gserve", | ||
"start:devserver": "yarn build:deps && yarn start", | ||
"build": "gatsby build", | ||
"serve": "gatsby serve", | ||
"clean": "gatsby clean", | ||
|
@@ -29,6 +30,7 @@ | |
"gatsby-source-faker": "^5.7.0", | ||
"gatsby-source-filesystem": "^5.7.0", | ||
"gatsby-transformer-sharp": "^5.7.0", | ||
"pino-pretty": "^10.0.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not seeing this used anywhere... also |
||
"postcss": "^8.4.21", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
import { isGatsbyHosting } from "../../utils/functions"; | ||
|
||
export default function handler(req, res) { | ||
res.code(200).send({ splat: req.params.splat }); | ||
if (isGatsbyHosting(res)) { | ||
res.status(200).send({ splat: req.params.splat }); | ||
} else { | ||
res.code(200).send({ splat: req.params.splat }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
import { isGatsbyHosting } from "../../utils/functions"; | ||
|
||
export default function handler(req, res) { | ||
res.code(200).send(req.params); | ||
if (isGatsbyHosting(res)) { | ||
res.status(200).send(req.params); | ||
} else { | ||
res.code(200).send(req.params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
import { isGatsbyHosting } from "../../utils/functions"; | ||
|
||
export default function handler(req, res) { | ||
res.code(200).send(req.params); | ||
if (isGatsbyHosting(res)) { | ||
res.status(200).send(req.params); | ||
} else { | ||
res.code(200).send(req.params); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
integration-tests/plugin-fastify/src/components/LazyComponent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as React from "react"; | ||
|
||
export default function LazyComponent() { | ||
return ( | ||
<div> | ||
<h1 data-lazy="true">Lazy Component</h1> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
import * as React from "react"; | ||
import { Link } from "gatsby"; | ||
|
||
const LazyComponent = React.lazy(() => import(`./LazyComponent`)); | ||
|
||
export default function PostPage({ title, content }) { | ||
return ( | ||
<article> | ||
<Link to="/">Return to Home</Link> | ||
|
||
<h1>{title}</h1> | ||
<div dangerouslySetInnerHTML={{ __html: content }} /> | ||
|
||
<React.Suspense fallback={<div>Loading</div>}> | ||
<LazyComponent /> | ||
</React.Suspense> | ||
</article> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
outline: 2px solid red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function isGatsbyHosting(response) { | ||
return response.setHeader !== undefined; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+202 KB
...in-fastify/src/__tests__/__files__/public/_gatsby/image/hash/hash/indonesia.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/gatsby-plugin-fastify/src/__tests__/__files__/public/app-hash.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("Hello from app-hash.js"); |
1 change: 1 addition & 0 deletions
1
packages/gatsby-plugin-fastify/src/__tests__/__files__/public/component-fake-hash.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("Hellow from component-fake-hash.js"); |
1 change: 1 addition & 0 deletions
1
packages/gatsby-plugin-fastify/src/__tests__/__files__/public/css-hash.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
body { border: 1px solid red; } |
1 change: 1 addition & 0 deletions
1
packages/gatsby-plugin-fastify/src/__tests__/__files__/public/fake-chunk.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("Hello from fake-chunk.js"); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was getting
gatsby-plugin-fastify module not found
(iirc on the exact error)...I tried a few things and only this worked. I'll try again while I'm making changes and put in the exact error, maybe you have another fix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird...it kinda makes sense...but why has it been working is just as strange.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya know what...this isn't automated...it probably hasn't been run since I made this change.