@zachhandley/ez-i18n 0.3.11 → 0.3.12

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/dist/index.js CHANGED
@@ -894,7 +894,7 @@ function __deepMerge(target, ...sources) {
894
894
  function getPublicLoaderCode() {
895
895
  return `
896
896
  async function __loadPublicJson(url, absolutePath) {
897
- // Browser environment - use fetch
897
+ // Browser environment - use fetch with relative URL
898
898
  if (typeof window !== 'undefined') {
899
899
  return fetch(url).then(r => r.json());
900
900
  }
@@ -907,8 +907,13 @@ async function __loadPublicJson(url, absolutePath) {
907
907
  !globalThis.process?.versions?.node; // No Node.js process
908
908
 
909
909
  if (isEdgeRuntime) {
910
- // Edge runtime - use fetch (relative URLs work in request context)
911
- return fetch(url).then(r => r.json());
910
+ // Edge runtime - need absolute URL for fetch
911
+ // Priority: Astro site config > middleware-set origin > relative (hope for the best)
912
+ const origin = import.meta.env.SITE?.replace(/\\/$/, '') ||
913
+ globalThis.__EZ_I18N_ORIGIN__ ||
914
+ '';
915
+ const fetchUrl = origin ? origin + url : url;
916
+ return fetch(fetchUrl).then(r => r.json());
912
917
  }
913
918
 
914
919
  // Traditional Node.js SSR - read from filesystem
@@ -40,6 +40,9 @@ var onRequest = defineMiddleware(async ({ cookies, request, locals, redirect },
40
40
  }
41
41
  locals.locale = locale;
42
42
  try {
43
+ if (!import.meta.env.SITE && !globalThis.__EZ_I18N_ORIGIN__) {
44
+ globalThis.__EZ_I18N_ORIGIN__ = url.origin;
45
+ }
43
46
  const { loadTranslations } = await import("ez-i18n:translations");
44
47
  locals.translations = await loadTranslations(locale);
45
48
  globalThis.__EZ_I18N_SSR__ = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zachhandley/ez-i18n",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },