настройка докер-связи с бэком
This commit is contained in:
1 parent
29f788ed9a
commit
9fc422eb02
6 files changed
+46
-14
No files matched your search
+8
-8
@@ -5,6 +5,11 @@ WORKDIR /app
|
|||||||
|
|
||||||
ENV PUPPETEER_SKIP_DOWNLOAD=true
|
ENV PUPPETEER_SKIP_DOWNLOAD=true
|
||||||
|
|
||||||
|
ARG SITE_URL
|
||||||
|
ARG PRERENDER_API_URL
|
||||||
|
ENV SITE_URL=${SITE_URL}
|
||||||
|
ENV PRERENDER_API_URL=${PRERENDER_API_URL}
|
||||||
|
|
||||||
# Копируем зависимости
|
# Копируем зависимости
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
@@ -20,18 +25,13 @@ RUN node scripts/prerender.js
|
|||||||
# ========== СТАДИЯ 2: СЕРВЕР ==========
|
# ========== СТАДИЯ 2: СЕРВЕР ==========
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
ENV BACKEND_UPSTREAM=pvh-backend:8000
|
||||||
|
|
||||||
# Копируем собранные файлы из стадии 1
|
# Копируем собранные файлы из стадии 1
|
||||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
COPY nginx/default.conf.template /etc/nginx/templates/default.conf.template
|
||||||
|
|
||||||
# Конфиг для SPA (чтобы react-router работал)
|
# Конфиг для SPA (чтобы react-router работал)
|
||||||
RUN echo 'server { \
|
|
||||||
listen 80; \
|
|
||||||
location / { \
|
|
||||||
root /usr/share/nginx/html; \
|
|
||||||
try_files $uri $uri/ /index.html; \
|
|
||||||
} \
|
|
||||||
}' > /etc/nginx/conf.d/default.conf
|
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://${BACKEND_UPSTREAM};
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
User-agent: *
|
User-agent: *
|
||||||
Allow: /
|
Allow: /
|
||||||
|
|
||||||
Sitemap: https://pvh.projects.rustprogersteam.ru/sitemap.xml
|
Sitemap: /sitemap.xml
|
||||||
@@ -3,10 +3,16 @@ import { resolve, dirname } from "path";
|
|||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const prerenderApiUrl = process.env.PRERENDER_API_URL;
|
||||||
|
|
||||||
async function getProducts() {
|
async function getProducts() {
|
||||||
|
if (!prerenderApiUrl) {
|
||||||
|
console.warn('PRERENDER_API_URL is not configured; skipping product pre-rendering.');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('https://pvh.projects.rustprogersteam.ru/api/productList');
|
const response = await fetch(`${prerenderApiUrl.replace(/\/$/, '')}/productList`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (Array.isArray(data)) {
|
if (Array.isArray(data)) {
|
||||||
@@ -215,7 +221,8 @@ ${urls.map(item => ` <url>
|
|||||||
</urlset>`;
|
</urlset>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sitemapContent = generateSitemap(urls, 'https://pvh.projects.rustprogersteam.ru');
|
const sitemapBaseUrl = process.env.SITE_URL?.replace(/\/$/, '') || 'http://localhost:5173';
|
||||||
|
const sitemapContent = generateSitemap(urls, sitemapBaseUrl);
|
||||||
const sitemapPath = resolve(distPath, 'sitemap.xml');
|
const sitemapPath = resolve(distPath, 'sitemap.xml');
|
||||||
writeFileSync(sitemapPath, sitemapContent);
|
writeFileSync(sitemapPath, sitemapContent);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ import axios, { AxiosInstance } from 'axios';
|
|||||||
class ApiClient {
|
class ApiClient {
|
||||||
private axiosInstance: AxiosInstance;
|
private axiosInstance: AxiosInstance;
|
||||||
|
|
||||||
constructor(baseURL: string = 'https://pvh.projects.rustprogersteam.ru/api') {
|
constructor(baseURL: string = import.meta.env.VITE_API_URL || '/api') {
|
||||||
this.axiosInstance = axios.create({
|
this.axiosInstance = axios.create({
|
||||||
baseURL,
|
baseURL,
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
|
|||||||
+10
-2
@@ -8,7 +8,7 @@ export default defineConfig({
|
|||||||
plugins: [
|
plugins: [
|
||||||
react(),
|
react(),
|
||||||
Sitemap({
|
Sitemap({
|
||||||
hostname: 'https://pvh.projects.rustprogersteam.ru',
|
hostname: process.env.SITE_URL || 'http://localhost:5173',
|
||||||
exclude: ['/admin', '/profile'],
|
exclude: ['/admin', '/profile'],
|
||||||
readable: true,
|
readable: true,
|
||||||
outDir: './dist',
|
outDir: './dist',
|
||||||
@@ -18,12 +18,20 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
host: '0.0.0.0', // Слушаем все интерфейсы
|
host: '0.0.0.0', // Слушаем все интерфейсы
|
||||||
port: 5173,
|
port: 5173,
|
||||||
allowedHosts: ['pvh.projects.rustprogersteam.ru'],
|
allowedHosts: process.env.VITE_ALLOWED_HOSTS?.split(',').map((host) => host.trim()),
|
||||||
strictPort: true, // Запрещаем автоматический выбор порта
|
strictPort: true, // Запрещаем автоматический выбор порта
|
||||||
hmr: {
|
hmr: {
|
||||||
clientPort: 5173, // Важно для HMR в Docker
|
clientPort: 5173, // Важно для HMR в Docker
|
||||||
},
|
},
|
||||||
// Разрешаем CORS для внешних запросов
|
// Разрешаем CORS для внешних запросов
|
||||||
|
proxy: process.env.VITE_API_PROXY_TARGET
|
||||||
|
? {
|
||||||
|
'/api': {
|
||||||
|
target: process.env.VITE_API_PROXY_TARGET,
|
||||||
|
changeOrigin: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
cors: true
|
cors: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user