@gsa-tts/graymatter-ui 0.3.21 → 0.3.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/layouts/GlobalAppLayout.astro +13 -2
- package/src/utils/getAppUrls.ts +31 -11
package/package.json
CHANGED
|
@@ -8,7 +8,8 @@ import MobileBottomNav from '../components/MobileBottomNav.svelte';
|
|
|
8
8
|
import MobileSideMenu from '../components/MobileSideMenu.svelte';
|
|
9
9
|
import Logo from '../components/Logo.svelte';
|
|
10
10
|
import { siteName } from '../constants';
|
|
11
|
-
import {
|
|
11
|
+
import { getUrlFromBase } from '../helpers/url.js';
|
|
12
|
+
import { getSecret } from 'astro:env/server';
|
|
12
13
|
|
|
13
14
|
const {
|
|
14
15
|
componentOptions = {},
|
|
@@ -24,7 +25,17 @@ const {
|
|
|
24
25
|
hideDiscover = true,
|
|
25
26
|
} = Astro.props;
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
// Use getSecret directly for better environment variable handling
|
|
29
|
+
const chatUrl = getSecret('CHAT_URL') || getSecret('PUBLIC_CHAT_URL');
|
|
30
|
+
const consoleUrl = getSecret('CONSOLE_URL') || getSecret('PUBLIC_CONSOLE_URL');
|
|
31
|
+
const apiUrl = getSecret('API_URL') || getSecret('PUBLIC_API_URL');
|
|
32
|
+
const discoverUrl =
|
|
33
|
+
getSecret('DISCOVER_URL') || getSecret('PUBLIC_DISCOVER_URL');
|
|
34
|
+
|
|
35
|
+
const chat = chatUrl || '#';
|
|
36
|
+
const console = consoleUrl || '#';
|
|
37
|
+
const api = apiUrl || getUrlFromBase('/api/documentation');
|
|
38
|
+
const discover = discoverUrl || '#';
|
|
28
39
|
---
|
|
29
40
|
|
|
30
41
|
<BaseLayout title={pageTitle} {gtmID} {description} {openGraphImage}>
|
package/src/utils/getAppUrls.ts
CHANGED
|
@@ -66,7 +66,7 @@ function processUrl(url: string | undefined, fallback: string): string {
|
|
|
66
66
|
*
|
|
67
67
|
* @param envArg - Optional environment object to use instead of `import.meta.env`.
|
|
68
68
|
* Useful for testing or when you want to override environment variables.
|
|
69
|
-
* If not provided, uses
|
|
69
|
+
* If not provided, uses `process.env` (server) or `import.meta.env` (client).
|
|
70
70
|
*
|
|
71
71
|
* @returns An object containing processed URLs/paths for each application section:
|
|
72
72
|
* - `chat`: Chat application URL or path
|
|
@@ -102,31 +102,51 @@ function processUrl(url: string | undefined, fallback: string): string {
|
|
|
102
102
|
* ```
|
|
103
103
|
*
|
|
104
104
|
* @remarks
|
|
105
|
+
* - Uses `process.env` in server context, `import.meta.env` in client context
|
|
106
|
+
* - Supports both `CHAT_URL` and `PUBLIC_CHAT_URL` naming conventions
|
|
105
107
|
* - URLs are processed through `processUrl()` which handles both absolute and relative URLs
|
|
106
|
-
* - Relative URLs are processed through `getUrlFromBase()` to create full URLs
|
|
107
108
|
* - Missing environment variables result in fallback values (`#` for most, `/api/documentation` for API)
|
|
108
109
|
* - Warnings are logged in development when environment variables are missing
|
|
109
|
-
* - The function is designed to work with Vite's `import.meta.env`
|
|
110
|
+
* - The function is designed to work with both Vite's `import.meta.env` and Node.js `process.env`
|
|
111
|
+
* - Note: Astro layouts (like GlobalAppLayout.astro) use `getSecret()` directly for better performance
|
|
110
112
|
*
|
|
111
113
|
* @see {@link processUrl} - URL processing logic
|
|
112
114
|
* @see {@link getUrlFromBase} - Base URL resolution
|
|
113
115
|
*/
|
|
114
116
|
export function getAppUrls(envArg?: Record<string, string | undefined>) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
+
// If envArg is provided, use it directly (for testing)
|
|
118
|
+
if (envArg) {
|
|
119
|
+
const chatUrl = envArg.CHAT_URL || envArg.PUBLIC_CHAT_URL;
|
|
120
|
+
const consoleUrl = envArg.CONSOLE_URL || envArg.PUBLIC_CONSOLE_URL;
|
|
121
|
+
const apiUrl = envArg.API_URL || envArg.PUBLIC_API_URL;
|
|
122
|
+
const discoverUrl = envArg.DISCOVER_URL || envArg.PUBLIC_DISCOVER_URL;
|
|
117
123
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
warnIfMissing('chat', chatUrl);
|
|
125
|
+
warnIfMissing('console', consoleUrl);
|
|
126
|
+
warnIfMissing('api', apiUrl);
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
chat: processUrl(chatUrl, '#'),
|
|
130
|
+
console: processUrl(consoleUrl, '#'),
|
|
131
|
+
api: processUrl(apiUrl, getUrlFromBase('/api/documentation')),
|
|
132
|
+
discover: processUrl(discoverUrl, '#'),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Use process.env in server context, import.meta.env in client context
|
|
137
|
+
const env = typeof window === 'undefined' ? process.env : import.meta.env;
|
|
138
|
+
const chatUrl = env.CHAT_URL || env.PUBLIC_CHAT_URL;
|
|
139
|
+
const consoleUrl = env.CONSOLE_URL || env.PUBLIC_CONSOLE_URL;
|
|
140
|
+
const apiUrl = env.API_URL || env.PUBLIC_API_URL;
|
|
141
|
+
const discoverUrl = env.DISCOVER_URL || env.PUBLIC_DISCOVER_URL;
|
|
122
142
|
|
|
123
143
|
warnIfMissing('chat', chatUrl);
|
|
124
144
|
warnIfMissing('console', consoleUrl);
|
|
125
145
|
warnIfMissing('api', apiUrl);
|
|
126
146
|
|
|
127
147
|
return {
|
|
128
|
-
chat: processUrl(chatUrl,
|
|
129
|
-
console: processUrl(consoleUrl,
|
|
148
|
+
chat: processUrl(chatUrl, '#'),
|
|
149
|
+
console: processUrl(consoleUrl, '#'),
|
|
130
150
|
api: processUrl(apiUrl, getUrlFromBase('/api/documentation')),
|
|
131
151
|
discover: processUrl(discoverUrl, '#'),
|
|
132
152
|
};
|