From 376d8b8654dedf91a0f6ee8d6db8fb823bf2d41e Mon Sep 17 00:00:00 2001 From: Ruslan Matkovskyi Date: Wed, 25 Oct 2023 16:30:53 +0200 Subject: [PATCH 1/5] #600951: [templates/nextjs] fixed plugin of cors header There was missed common nextjs of headers config --- .../templates/nextjs/src/lib/next-config/plugins/cors-header.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js b/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js index b8f6385210..ba1b415efb 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js +++ b/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js @@ -10,6 +10,7 @@ const corsHeaderPlugin = (nextConfig = {}) => { return Object.assign({}, nextConfig, { async headers() { return [ + ...await nextConfig?.headers(), { source: '/_next/:path*', headers: [{ key: 'Access-Control-Allow-Origin', value: config.sitecoreApiHost }], From c1c5f9f1dd7f6d8b0bb6828738432516936b5378 Mon Sep 17 00:00:00 2001 From: Ruslan Matkovskyi Date: Wed, 25 Oct 2023 16:37:54 +0200 Subject: [PATCH 2/5] #600951: changed CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2540d23408..c88f1a1ea3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Our versioning strategy is as follows: * `[templates/nextjs]` Enable client-only BYOC component imports. Client-only components can be imported through src/byoc/index.client.ts. Hybrid (server render with client hydration) components can be imported through src/byoc/index.hybrid.ts. BYOC scaffold logic is also moved from nextjs-sxa addon into base template ([#1628](https://github.com/Sitecore/jss/pull/1628)[#1636](https://github.com/Sitecore/jss/pull/1636)) * `[templates/nextjs]` Import SitecoreForm component into sample nextjs app ([#1628](https://github.com/Sitecore/jss/pull/1628)) * `[sitecore-jss-nextjs]` (Vercel/Sitecore) Deployment Protection Bypass support for editing integration. ([#1634](https://github.com/Sitecore/jss/pull/1634)) +* `[templates/nextjs]` Fix custom headers. Now in cors-header plugin extends custom headers from next.config.js file. ([#1637](https://github.com/Sitecore/jss/pull/1637)) ### 🐛 Bug Fixes From 158ff8a2998a6a0cb659cf128f6da0336a428a80 Mon Sep 17 00:00:00 2001 From: Ruslan Matkovskyi Date: Wed, 25 Oct 2023 21:51:44 +0200 Subject: [PATCH 3/5] #600951: fixed styling of code --- .../templates/nextjs/src/lib/next-config/plugins/cors-header.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js b/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js index ba1b415efb..d1727c1708 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js +++ b/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js @@ -10,7 +10,7 @@ const corsHeaderPlugin = (nextConfig = {}) => { return Object.assign({}, nextConfig, { async headers() { return [ - ...await nextConfig?.headers(), + ...await nextConfig.headers(), { source: '/_next/:path*', headers: [{ key: 'Access-Control-Allow-Origin', value: config.sitecoreApiHost }], From f91ac223a6eba30ec25451476f6768bf0403ce3a Mon Sep 17 00:00:00 2001 From: Ruslan Matkovskyi Date: Wed, 25 Oct 2023 21:54:17 +0200 Subject: [PATCH 4/5] #600951: reverted fixed styling code --- .../templates/nextjs/src/lib/next-config/plugins/cors-header.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js b/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js index d1727c1708..ba1b415efb 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js +++ b/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js @@ -10,7 +10,7 @@ const corsHeaderPlugin = (nextConfig = {}) => { return Object.assign({}, nextConfig, { async headers() { return [ - ...await nextConfig.headers(), + ...await nextConfig?.headers(), { source: '/_next/:path*', headers: [{ key: 'Access-Control-Allow-Origin', value: config.sitecoreApiHost }], From 7c2e13b68a70dbc53f0c2250cd7f75465de50b6f Mon Sep 17 00:00:00 2001 From: Ruslan Matkovskyi Date: Wed, 25 Oct 2023 23:35:43 +0200 Subject: [PATCH 5/5] #600951: refactoring extend headers --- .../nextjs/src/lib/next-config/plugins/cors-header.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js b/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js index ba1b415efb..310c02def8 100644 --- a/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js +++ b/packages/create-sitecore-jss/src/templates/nextjs/src/lib/next-config/plugins/cors-header.js @@ -9,8 +9,9 @@ const corsHeaderPlugin = (nextConfig = {}) => { } return Object.assign({}, nextConfig, { async headers() { + const extendHeaders = typeof nextConfig.headers === "function" ? await nextConfig.headers() : []; return [ - ...await nextConfig?.headers(), + ...await extendHeaders, { source: '/_next/:path*', headers: [{ key: 'Access-Control-Allow-Origin', value: config.sitecoreApiHost }],