summaryrefslogtreecommitdiff
path: root/src/config
diff options
context:
space:
mode:
authorIwanIDev <iwan@iwani.dev>2026-03-19 20:16:23 +0000
committerIwanIDev <iwan@iwani.dev>2026-03-19 20:16:23 +0000
commita706dcf6a9b91ef2c3d1e1d28449b9b8e0e8187d (patch)
treeca3ea838179472713e1e2d089813f0f39ac72adb /src/config
parent572a393440b39a838b99227ba2222a210a495fac (diff)
Add support for headless Drupal integration with environment variables and Docker setup
- Create .env.example for environment variable configuration - Update Dockerfile to accept Drupal-related build arguments - Enhance docker_build.yml to pass environment variables during Docker build - Add drupalClient and env configuration for API interaction - Implement local development instructions and Docker deployment steps in README - Add drupal and mariadb services to docker-stack.yml for complete setup - Update package.json and bun.lock to include axios and drupal-jsonapi-params dependencies - Add TypeScript definitions for new environment variables
Diffstat (limited to 'src/config')
-rw-r--r--src/config/env.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/config/env.ts b/src/config/env.ts
new file mode 100644
index 0000000..c530b3a
--- /dev/null
+++ b/src/config/env.ts
@@ -0,0 +1,23 @@
+const trimTrailingSlashes = (value: string): string => value.replace(/\/+$/, '')
+
+const normalizePathPrefix = (value: string): string => {
+ if (!value) {
+ return '/jsonapi'
+ }
+
+ return value.startsWith('/') ? value : `/${value}`
+}
+
+export const drupalEnv = {
+ baseUrl: trimTrailingSlashes(import.meta.env.VITE_DRUPAL_BASE_URL ?? ''),
+ apiPrefix: normalizePathPrefix(import.meta.env.VITE_DRUPAL_API_PREFIX ?? '/jsonapi'),
+ authToken: import.meta.env.VITE_DRUPAL_AUTH_TOKEN ?? '',
+}
+
+export const getDrupalApiBaseUrl = (): string => {
+ if (!drupalEnv.baseUrl) {
+ throw new Error('Missing VITE_DRUPAL_BASE_URL. Set it in your environment before using the Drupal client.')
+ }
+
+ return `${drupalEnv.baseUrl}${drupalEnv.apiPrefix}`
+}