-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
to support for passing a nonce to the rehydration script --------- Co-authored-by: Lenz Weber-Tronic <[email protected]>
- Loading branch information
1 parent
bb6bee5
commit e466b37
Showing
13 changed files
with
318 additions
and
66 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SECRET={"alg":"A256CBC","ext":true,"k":"yZrgd8urZnVpOSjC22EUNIDJZbmvEL4xApt_eraMsaU","key_ops":["encrypt","decrypt"],"kty":"oct"} |
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
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,7 +1,16 @@ | ||
import { headers } from "next/headers"; | ||
import { ApolloWrapper } from "../ApolloWrapper"; | ||
import { cloakSSROnlySecret } from "ssr-only-secrets"; | ||
|
||
export default function Layout({ children }: React.PropsWithChildren) { | ||
export default async function Layout({ children }: React.PropsWithChildren) { | ||
// force this into definitely rendering on the server, and dynamically | ||
console.log(headers().toString().substring(0, 0)); | ||
return children; | ||
const nonce = headers().get("x-nonce-param") ?? undefined; | ||
return ( | ||
<ApolloWrapper | ||
nonce={nonce ? await cloakSSROnlySecret(nonce, "SECRET") : undefined} | ||
> | ||
{children} | ||
</ApolloWrapper> | ||
); | ||
} |
2 changes: 1 addition & 1 deletion
2
integration-test/src/app/cc/layout.tsx → ...gration-test/src/app/cc/static/layout.tsx
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,48 @@ | ||
import { makeExecutableSchema } from "@graphql-tools/schema"; | ||
import gql from "graphql-tag"; | ||
|
||
const typeDefs = gql` | ||
type Product { | ||
id: String! | ||
title: String! | ||
} | ||
type Query { | ||
products: [Product!]! | ||
} | ||
`; | ||
|
||
const resolvers = { | ||
Query: { | ||
products: async () => [ | ||
{ | ||
id: "product:5", | ||
title: "Soft Warm Apollo Beanie", | ||
}, | ||
{ | ||
id: "product:2", | ||
title: "Stainless Steel Water Bottle", | ||
}, | ||
{ | ||
id: "product:3", | ||
title: "Athletic Baseball Cap", | ||
}, | ||
{ | ||
id: "product:4", | ||
title: "Baby Onesies", | ||
}, | ||
{ | ||
id: "product:1", | ||
title: "The Apollo T-Shirt", | ||
}, | ||
{ | ||
id: "product:6", | ||
title: "The Apollo Socks", | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export const schema = makeExecutableSchema({ | ||
typeDefs, | ||
resolvers, | ||
}); |
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,33 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export function middleware(request: NextRequest) { | ||
const nonce = request.nextUrl.searchParams.get("nonce"); | ||
if (nonce) { | ||
// we set a fixed nonce here so we can test correct and incorrect nonce values | ||
const validNonce = "8IBTHwOdqNKAWeKl7plt8g=="; | ||
// 'unsafe-eval' for `react-refresh` | ||
const contentSecurityPolicyHeaderValue = `default-src 'self'; script-src 'nonce-${validNonce}' 'strict-dynamic' 'unsafe-eval';`; | ||
|
||
const requestHeaders = new Headers(request.headers); | ||
// valid nonce for next | ||
requestHeaders.set("x-nonce", validNonce); | ||
// potentially invalid nonce for `ApolloNextAppProvider` | ||
requestHeaders.set("x-nonce-param", nonce); | ||
requestHeaders.set( | ||
"Content-Security-Policy", | ||
contentSecurityPolicyHeaderValue | ||
); | ||
|
||
const response = NextResponse.next({ | ||
request: { | ||
headers: requestHeaders, | ||
}, | ||
}); | ||
response.headers.set( | ||
"Content-Security-Policy", | ||
contentSecurityPolicyHeaderValue | ||
); | ||
|
||
return response; | ||
} | ||
} |
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
Oops, something went wrong.