diff options
| author | Fuwn <[email protected]> | 2026-03-22 03:45:51 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-22 03:50:07 +0000 |
| commit | a1a747d6b46cc653f1716f6f71cf02284b0f20cd (patch) | |
| tree | 01c0e6f9bcef809efc07f7a1032f49b9d58e8faa /src/lib/Utility/appOrigin.ts | |
| parent | refactor: extract app origin config (diff) | |
| download | due.moe-a1a747d6b46cc653f1716f6f71cf02284b0f20cd.tar.xz due.moe-a1a747d6b46cc653f1716f6f71cf02284b0f20cd.zip | |
refactor: centralise site origin usage
Diffstat (limited to 'src/lib/Utility/appOrigin.ts')
| -rw-r--r-- | src/lib/Utility/appOrigin.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/lib/Utility/appOrigin.ts b/src/lib/Utility/appOrigin.ts index 8d534d81..cdc53995 100644 --- a/src/lib/Utility/appOrigin.ts +++ b/src/lib/Utility/appOrigin.ts @@ -23,10 +23,20 @@ export const appOrigin = () => { return dev ? LOCAL_ORIGIN : PRODUCTION_ORIGIN; }; +export const siteUrl = (path = "/") => + `${appOrigin()}${path.startsWith("/") ? path : `/${path}`}`; + export const isLocalApp = () => { const { hostname } = new URL(appOrigin()); return dev || isPrivateHostname(hostname); }; +export const appOriginHeaders = ( + headers: Record<string, string> = {}, +): Record<string, string> => ({ + ...headers, + "Access-Control-Allow-Origin": appOrigin(), +}); + export { LOCAL_ORIGIN, PRODUCTION_ORIGIN }; |