Skip to content

Commit

Permalink
Fix PNA preflight headers (#1709)
Browse files Browse the repository at this point in the history
Co-authored-by: Fran Dios <[email protected]>
  • Loading branch information
wizardlyhel and frandiox authored Jan 30, 2024
1 parent 4c3425a commit 06320ee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/violet-seas-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-hydrogen': patch
---

Fix local asset path to Oxygen to return valid preflight headers
12 changes: 12 additions & 0 deletions packages/cli/src/lib/mini-oxygen/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ export function buildAssetsUrl(assetsPort: number) {
export function createAssetsServer(buildPathClient: string) {
return createServer(async (req: IncomingMessage, res: ServerResponse) => {
// Similar headers to Shopify CDN
if (req.method === 'OPTIONS') {
// Setting PNA preflight headers
// https://developer.chrome.com/blog/private-network-access-preflight
res.setHeader('Access-Control-Allow-Origin', req.headers.origin || '*');
res.setHeader('Access-Control-Allow-Credentials', 'true');
res.setHeader('Access-Control-Allow-Private-Network', 'true');
res.setHeader('Access-Control-Max-Age', '86400');
res.writeHead(204);
res.end();
return;
}

res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('X-Content-Type-Options', 'nosniff');

Expand Down
2 changes: 1 addition & 1 deletion templates/demo-store/customer-accountapi.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type CustomerAddressUpdateMutation = {
customerAddressUpdate?: CustomerAccountAPI.Maybe<{
userErrors: Array<
Pick<
CustomerAccountAPI.UserErrorsAddressUserErrors,
CustomerAccountAPI.UserErrorsCustomerAddressUserErrors,
'code' | 'field' | 'message'
>
>;
Expand Down

0 comments on commit 06320ee

Please sign in to comment.