@crm-market/template-shared 1.0.4 → 1.0.5

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.
@@ -185,8 +185,7 @@ export default defineComponent({
185
185
  const resolveImageUrl = (url: string) => {
186
186
  if (!url) return '';
187
187
  if (url.startsWith('http')) return url;
188
- const config = useRuntimeConfig();
189
- const apiBase = config.public.apiBase || 'http://localhost:3001/api';
188
+ const apiBase = getApiBaseUrl();
190
189
  const baseUrl = apiBase.replace('/api', '');
191
190
  return `${baseUrl}${url}`;
192
191
  };
@@ -167,8 +167,7 @@ export default defineComponent({
167
167
  const resolveImageUrl = (url: string) => {
168
168
  if (!url) return '';
169
169
  if (url.startsWith('http')) return url;
170
- const config = useRuntimeConfig();
171
- const apiBase = config.public.apiBase || 'http://localhost:3001/api';
170
+ const apiBase = getApiBaseUrl();
172
171
  const baseUrl = apiBase.replace('/api', '');
173
172
  return `${baseUrl}${url}`;
174
173
  };
@@ -195,8 +195,7 @@ export default defineComponent({
195
195
  const resolveImageUrl = (url: string) => {
196
196
  if (!url) return '';
197
197
  if (url.startsWith('http')) return url;
198
- const config = useRuntimeConfig();
199
- const apiBase = config.public.apiBase || 'http://localhost:3001/api';
198
+ const apiBase = getApiBaseUrl();
200
199
  const baseUrl = apiBase.replace('/api', '');
201
200
  return `${baseUrl}${url}`;
202
201
  };
@@ -1,5 +1,6 @@
1
1
  import { ref, computed } from 'vue';
2
2
  import { useRuntimeConfig } from '#imports';
3
+ import { getApiBaseUrl } from '../utils/api';
3
4
  import { useSiteConfig } from './useSiteConfig';
4
5
 
5
6
  interface Category {
@@ -34,7 +35,7 @@ export const useCategories = () => {
34
35
  }
35
36
 
36
37
  const response = await $fetch<{ categories: Category[] }>('/site-template/public/store/categories', {
37
- baseURL: config.public.apiBase || 'http://localhost:3001/api',
38
+ baseURL: getApiBaseUrl(),
38
39
  params: { token },
39
40
  });
40
41
 
@@ -65,7 +65,7 @@ export const useCheckout = () => {
65
65
 
66
66
  const response = await $fetch<{ id: string }>('/order', {
67
67
  method: 'POST',
68
- baseURL: config.public.apiBase || 'http://localhost:3001/api',
68
+ baseURL: getApiBaseUrl(),
69
69
  body: orderData,
70
70
  });
71
71
 
@@ -88,7 +88,7 @@ export const useCheckout = () => {
88
88
 
89
89
  try {
90
90
  const response = await $fetch(`/order/${id}`, {
91
- baseURL: config.public.apiBase || 'http://localhost:3001/api',
91
+ baseURL: getApiBaseUrl(),
92
92
  });
93
93
 
94
94
  return response;
@@ -1,5 +1,6 @@
1
1
  import { ref, computed } from 'vue';
2
2
  import { useRuntimeConfig } from '#imports';
3
+ import { getApiBaseUrl } from '../utils/api';
3
4
  import { useSiteConfig } from './useSiteConfig';
4
5
 
5
6
  interface Product {
@@ -52,7 +53,7 @@ export const useProducts = () => {
52
53
  };
53
54
 
54
55
  const response = await $fetch<{ products: Product[]; total: number }>('/site-template/public/store/products', {
55
- baseURL: config.public.apiBase || 'http://localhost:3001/api',
56
+ baseURL: getApiBaseUrl(),
56
57
  params,
57
58
  });
58
59
 
@@ -79,7 +80,7 @@ export const useProducts = () => {
79
80
  }
80
81
 
81
82
  const response = await $fetch<{ product: Product }>(`/site-template/public/store/products/${productId}`, {
82
- baseURL: config.public.apiBase || 'http://localhost:3001/api',
83
+ baseURL: getApiBaseUrl(),
83
84
  params: { token },
84
85
  });
85
86
 
@@ -106,7 +107,7 @@ export const useProducts = () => {
106
107
  };
107
108
 
108
109
  const response = await $fetch<{ products: Product[]; total: number }>('/site-template/public/store/products', {
109
- baseURL: config.public.apiBase || 'http://localhost:3001/api',
110
+ baseURL: getApiBaseUrl(),
110
111
  params,
111
112
  });
112
113
 
@@ -1,5 +1,6 @@
1
1
  import { ref, computed } from 'vue';
2
2
  import { useRuntimeConfig, useRoute } from '#imports';
3
+ import { getApiBaseUrl } from '../utils/api';
3
4
 
4
5
  interface ColorScheme {
5
6
  primary?: string;
@@ -89,7 +90,7 @@ export const useSiteConfig = () => {
89
90
  const response = await $fetch<SiteConfig>(
90
91
  `/site-template/public/config/subdomain/${sub}`,
91
92
  {
92
- baseURL: config.public.apiBase || 'http://localhost:3001/api',
93
+ baseURL: getApiBaseUrl(),
93
94
  }
94
95
  );
95
96
 
package/nuxt.config.ts CHANGED
@@ -21,6 +21,8 @@ export default defineNuxtConfig({
21
21
  },
22
22
 
23
23
  runtimeConfig: {
24
+ // SSR-only: внутрішній URL бекенду (Docker мережа або localhost)
25
+ apiBaseInternal: process.env.API_BASE_INTERNAL || '',
24
26
  public: {
25
27
  apiBase: process.env.API_BASE_URL || 'http://localhost:3001/api',
26
28
  templateType: process.env.TEMPLATE_TYPE || 'electronics',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crm-market/template-shared",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "description": "Shared Nuxt 3 layer for CRM Market store templates (layouts, components, composables, pages)",
6
6
  "publishConfig": {
package/utils/api.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { useRuntimeConfig } from '#imports';
2
+
3
+ /**
4
+ * Повертає базовий URL для API-запитів.
5
+ * На сервері (SSR) використовує внутрішній URL Docker-мережі (якщо задано),
6
+ * на клієнті — завжди публічний URL.
7
+ */
8
+ export const getApiBaseUrl = (): string => {
9
+ const config = useRuntimeConfig();
10
+
11
+ // На сервері: використовуємо внутрішній URL якщо він задано
12
+ if (import.meta.server && config.apiBaseInternal) {
13
+ return config.apiBaseInternal as string;
14
+ }
15
+
16
+ return (config.public.apiBase as string) || 'http://localhost:3001/api';
17
+ };
package/utils/image.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { useRuntimeConfig } from '#imports';
2
+ import { getApiBaseUrl } from './api';
2
3
 
3
4
  /**
4
5
  * Перетворює відносні шляхи до зображень (/media/...) у повні URL
@@ -7,8 +8,7 @@ export const resolveImageUrl = (url: string | undefined | null): string => {
7
8
  if (!url) return '';
8
9
  if (url.startsWith('http') || url.startsWith('data:') || url.startsWith('blob:')) return url;
9
10
 
10
- const config = useRuntimeConfig();
11
- const apiBase = (config.public.apiBase as string) || 'http://localhost:3001/api';
11
+ const apiBase = getApiBaseUrl();
12
12
  // Видаляємо /api з кінця, щоб отримати базовий URL сервера
13
13
  const baseUrl = apiBase.replace(/\/api\/?$/, '');
14
14
  return `${baseUrl}${url.startsWith('/') ? '' : '/'}${url}`;