[web] Use the preferred null coalescing operator for env override (#2079)

This commit is contained in:
Manav Rathi
2024-06-10 14:37:01 +05:30
committed by GitHub
2 changed files with 10 additions and 16 deletions

View File

@@ -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
#

View File

@@ -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;