forked from bigcommerce/catalyst
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dynamic favicon from API (bigcommerce#1280)
- Loading branch information
1 parent
dd10d06
commit 27cbfd2
Showing
4 changed files
with
56 additions
and
0 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,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": minor | ||
--- | ||
|
||
Add dynamic favicon from API on a static route |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-disable check-file/folder-naming-convention */ | ||
/* | ||
* Proxy to the store's favicon URL | ||
* | ||
* If you would prefer to put a favicon image directly in your codebase, | ||
* delete this route folder and follow this guide: | ||
* | ||
* https://nextjs.org/docs/app/api-reference/file-conventions/metadata/app-icons | ||
* | ||
*/ | ||
|
||
import { client } from '~/client'; | ||
import { graphql } from '~/client/graphql'; | ||
|
||
const GET_FAVICON_QUERY = graphql(` | ||
query GetFavicon { | ||
site { | ||
settings { | ||
faviconUrl | ||
} | ||
} | ||
} | ||
`); | ||
|
||
export const GET = async () => { | ||
const { data } = await client.fetch({ | ||
document: GET_FAVICON_QUERY, | ||
}); | ||
|
||
const faviconUrl = data.site.settings?.faviconUrl; | ||
|
||
if (!faviconUrl) { | ||
return new Response(null, { | ||
status: 404, | ||
}); | ||
} | ||
|
||
// fetch the favicon URL and return the data directly (will be statically cached at build time) | ||
const faviconData = await fetch(faviconUrl).then((res) => res.arrayBuffer()); | ||
|
||
return new Response(faviconData, { | ||
headers: { | ||
'Content-Type': 'image/x-icon', | ||
}, | ||
}); | ||
}; | ||
|
||
export const dynamic = 'force-static'; |