настройка докер-связи с бэком
Build, Test and Push Flask App / docker-build-and-push (push) Successful in 1m44s
Build, Test and Push Flask App / deploy (push) Successful in 2m8s

This commit is contained in:
Joe_Peach committed 2026-09-28 18:07:35 +03:00
1 parent 29f788ed9a
commit 9fc422eb02
6 files changed
+46 -14

No files matched your search

+8 -8
View File
@@ -5,6 +5,11 @@ WORKDIR /app
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 ./
RUN npm ci
@@ -20,18 +25,13 @@ RUN node scripts/prerender.js
# ========== СТАДИЯ 2: СЕРВЕР ==========
FROM nginx:alpine
ENV BACKEND_UPSTREAM=pvh-backend:8000
# Копируем собранные файлы из стадии 1
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx/default.conf.template /etc/nginx/templates/default.conf.template
# Конфиг для 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
CMD ["nginx", "-g", "daemon off;"]
+17
View File
@@ -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
View File
@@ -1,4 +1,4 @@
User-agent: *
Allow: /
Sitemap: https://pvh.projects.rustprogersteam.ru/sitemap.xml
Sitemap: /sitemap.xml
+9 -2
View File
@@ -3,10 +3,16 @@ import { resolve, dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const prerenderApiUrl = process.env.PRERENDER_API_URL;
async function getProducts() {
if (!prerenderApiUrl) {
console.warn('PRERENDER_API_URL is not configured; skipping product pre-rendering.');
return [];
}
try {
const response = await fetch('https://pvh.projects.rustprogersteam.ru/api/productList');
const response = await fetch(`${prerenderApiUrl.replace(/\/$/, '')}/productList`);
const data = await response.json();
if (Array.isArray(data)) {
@@ -215,7 +221,8 @@ ${urls.map(item => ` <url>
</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');
writeFileSync(sitemapPath, sitemapContent);
+1 -1
View File
@@ -3,7 +3,7 @@ import axios, { AxiosInstance } from 'axios';
class ApiClient {
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({
baseURL,
timeout: 10000,
+10 -2
View File
@@ -8,7 +8,7 @@ export default defineConfig({
plugins: [
react(),
Sitemap({
hostname: 'https://pvh.projects.rustprogersteam.ru',
hostname: process.env.SITE_URL || 'http://localhost:5173',
exclude: ['/admin', '/profile'],
readable: true,
outDir: './dist',
@@ -18,12 +18,20 @@ export default defineConfig({
server: {
host: '0.0.0.0', // Слушаем все интерфейсы
port: 5173,
allowedHosts: ['pvh.projects.rustprogersteam.ru'],
allowedHosts: process.env.VITE_ALLOWED_HOSTS?.split(',').map((host) => host.trim()),
strictPort: true, // Запрещаем автоматический выбор порта
hmr: {
clientPort: 5173, // Важно для HMR в Docker
},
// Разрешаем CORS для внешних запросов
proxy: process.env.VITE_API_PROXY_TARGET
? {
'/api': {
target: process.env.VITE_API_PROXY_TARGET,
changeOrigin: true,
},
}
: undefined,
cors: true
}
})