diff options
| author | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
|---|---|---|
| committer | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
| commit | bce557cc2dc767628bed6aac87301a1be7c5431b (patch) | |
| tree | b51a051228d01fe3306cd7626d4a96768aadb944 /src/config/media-api | |
init commit
Diffstat (limited to 'src/config/media-api')
| -rw-r--r-- | src/config/media-api/browser.ts | 1 | ||||
| -rw-r--r-- | src/config/media-api/search-jwt.ts | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/config/media-api/browser.ts b/src/config/media-api/browser.ts new file mode 100644 index 0000000..91cf7c2 --- /dev/null +++ b/src/config/media-api/browser.ts @@ -0,0 +1 @@ +export const MEDIA_API_JWT = import.meta.env.BROWSER_MEDIA_API_JWT ?? ''; diff --git a/src/config/media-api/search-jwt.ts b/src/config/media-api/search-jwt.ts new file mode 100644 index 0000000..1f7e3d2 --- /dev/null +++ b/src/config/media-api/search-jwt.ts @@ -0,0 +1,27 @@ +export function shouldUseSearchJWT(url: URL): boolean { + // We should only ever use the "search" JWT on the server + if (!import.meta.env.SSR) { + return false; + } + + // Search API Endpoint + if (url.pathname.endsWith('/search')) { + return true; + } + + // All other endpoints should use the default JWT + return false; +} + +/** + * Creates the `Authorization` header using the App Store "search JWT" + * + * Note: this function specifically returns a bad value for a "browser" + * build so that the "search JWT" is removed from the browser payload + * by dead-code elimination + */ +export function makeSearchJWTAuthorizationHeader() { + return import.meta.env.SSR + ? { Authorization: `Bearer ${import.meta.env.SEARCH_MEDIA_API_JWT}` } + : { Authorization: '' }; +} |
