Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/vertex/lib/envConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
*/
import { stripTrailingSlash } from './utils';

/**
* Gets the default API URL fallback based on the current environment
* @returns {string} The default API URL
*/
export const getDefaultApiUrl = (): string => {
const env = getEnvironment().toLowerCase();
if (env === 'production') return 'https://vertex.airqo.net/api/v2';
if (env === 'staging') return 'https://staging-vertex.airqo.net/api/v2';
return 'http://localhost:3000';
};

/**
* Gets the API base URL from environment variables
* @returns {string} The API base URL
* @throws {Error} If API_URL is not defined
*/
export const getApiBaseUrl = (): string => {
const apiUrl = process.env.NEXT_PUBLIC_API_URL;

if (!apiUrl) {
throw new Error('NEXT_PUBLIC_API_URL environment variable is not defined');
}

const apiUrl = process.env.NEXT_PUBLIC_API_URL || getDefaultApiUrl();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return stripTrailingSlash(apiUrl);
};

Expand Down Expand Up @@ -153,7 +158,6 @@ export const getEnvConfig = () => {
*/
export const validateEnvironment = (): boolean => {
const required = [
'NEXT_PUBLIC_API_URL',
'NEXT_PUBLIC_API_TOKEN',
'NEXT_PUBLIC_CLOUDINARY_NAME',
'NEXT_PUBLIC_CLOUDINARY_PRESET',
Expand Down
5 changes: 3 additions & 2 deletions src/vertex/vertex.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
validateVertexConfig,
type VertexConfigInput,
} from "./core/config/vertex-config";
import { getDefaultApiUrl } from "./lib/envConstants";

const config: VertexConfigInput = {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
...defaultVertexConfig,
Expand All @@ -17,9 +18,9 @@ const config: VertexConfigInput = {
},
api: {
adapter: "airqo",
baseUrl: process.env.NEXT_PUBLIC_API_URL,
baseUrl: process.env.NEXT_PUBLIC_API_URL || getDefaultApiUrl(),
publicMeasurementsBaseUrl:
process.env.NEXT_PUBLIC_API_BASE_URL || "https://api.airqo.net",
process.env.NEXT_PUBLIC_API_BASE_URL || getDefaultApiUrl(),
},
auth: {
provider: "airqo",
Expand Down
Loading