From e23ac45fb3d753eeb725c7f6921267a7d5ff1aab Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Mon, 10 Jun 2024 14:29:44 +0530 Subject: [PATCH] [web] Use the preferred null coalescing operator for env override --- web/apps/photos/.env | 4 ++-- web/packages/shared/network/api.ts | 22 ++++++++-------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/web/apps/photos/.env b/web/apps/photos/.env index 766c3b861e..fe626d52d6 100644 --- a/web/apps/photos/.env +++ b/web/apps/photos/.env @@ -43,11 +43,11 @@ # The URL of the accounts app # -# NEXT_PUBLIC_ENTE_ACCOUNTS_URL = http://localhost:3001 +# NEXT_PUBLIC_ENTE_ACCOUNTS_URL = http://localhost:3001 # The URL of the payments app # -# NEXT_PUBLIC_ENTE_PAYMENTS_URL = http://localhost:3001 +# NEXT_PUBLIC_ENTE_PAYMENTS_URL = http://localhost:3001 # The URL for the shared albums deployment # diff --git a/web/packages/shared/network/api.ts b/web/packages/shared/network/api.ts index 6ce97a786d..f708e29e04 100644 --- a/web/packages/shared/network/api.ts +++ b/web/packages/shared/network/api.ts @@ -3,28 +3,22 @@ * API requests to museum. * * This defaults to "https://api.ente.io", Ente's own servers, but can be - * overridden when self hosting by setting the `NEXT_PUBLIC_ENTE_ENDPOINT` - * environment variable. + * overridden when self hosting or developing by setting the + * `NEXT_PUBLIC_ENTE_ENDPOINT` environment variable. */ -export const apiOrigin = () => customAPIOrigin() || "https://api.ente.io"; +export const apiOrigin = () => customAPIOrigin() ?? "https://api.ente.io"; /** * Return the overridden API origin, if one is defined by setting the - * `NEXT_PUBLIC_ENTE_ENDPOINT` environment variable to a non-empty value. + * `NEXT_PUBLIC_ENTE_ENDPOINT` environment variable. * * Otherwise return undefined. */ export const customAPIOrigin = () => - process.env.NEXT_PUBLIC_ENTE_ENDPOINT || undefined; + process.env.NEXT_PUBLIC_ENTE_ENDPOINT ?? undefined; /** Deprecated, use {@link apiOrigin} instead. */ -export const getEndpoint = () => { - const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT; - if (endpoint) { - return endpoint; - } - return "https://api.ente.io"; -}; +export const getEndpoint = apiOrigin; export const getUploadEndpoint = () => { const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT; @@ -39,10 +33,10 @@ export const getUploadEndpoint = () => { * * Defaults to our production instance, "https://accounts.ente.io", but can be * overridden by setting the `NEXT_PUBLIC_ENTE_ACCOUNTS_URL` environment - * variable to a non-empty value. + * variable. */ export const accountsAppURL = () => - process.env.NEXT_PUBLIC_ENTE_ACCOUNTS_URL || `https://accounts.ente.io`; + process.env.NEXT_PUBLIC_ENTE_ACCOUNTS_URL ?? `https://accounts.ente.io`; export const getAlbumsURL = () => { const albumsURL = process.env.NEXT_PUBLIC_ENTE_ALBUMS_ENDPOINT;