diff --git a/next.config.js b/next.config.js index 658404ac..7054ec5d 100644 --- a/next.config.js +++ b/next.config.js @@ -1,4 +1,8 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { + env: { + VITE_BASE_API_URL: process.env.VITE_BASE_API_URL + } +}; module.exports = nextConfig; diff --git a/util/api.ts b/util/api.ts index 795ea489..a48c273c 100644 --- a/util/api.ts +++ b/util/api.ts @@ -1,3 +1,4 @@ +import { getEnv } from "./env"; import { handleError } from "./helpers"; import { AcceptAdmissionRSVPRequest, @@ -11,7 +12,7 @@ import { EventType } from "./types"; -const APIv2 = "https://adonix.hackillinois.org"; +const APIv2 = getEnv("VITE_BASE_API_URL"); export const isAuthenticated = async (): Promise => { return (await getAuthToken()) !== null; diff --git a/util/env.ts b/util/env.ts new file mode 100644 index 00000000..86da6e4b --- /dev/null +++ b/util/env.ts @@ -0,0 +1,18 @@ +/** + * Type-safe environment variable access. + * Add new env variables to the `envVars` object below and to `next.config.js`'s `env` option. + */ + +const envVars = { + VITE_BASE_API_URL: process.env.VITE_BASE_API_URL +} as const; + +type EnvKey = keyof typeof envVars; + +export function getEnv(key: EnvKey): string { + const value = envVars[key]; + if (!value) { + throw new Error(`Missing required environment variable: ${key}`); + } + return value; +} diff --git a/wrangler.json b/wrangler.json index d9771a3e..6d476e03 100644 --- a/wrangler.json +++ b/wrangler.json @@ -7,5 +7,8 @@ "assets": { "directory": ".open-next/assets", "binding": "ASSETS" + }, + "vars": { + "VITE_BASE_API_URL": "https://adonix.hackillinois.org" } }