From ba8906ddefc8c51f014f1526fdd62b387944d569 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Mon, 30 Mar 2026 17:46:55 +0300 Subject: [PATCH] Integrate frontend UI into backend container and update Dockerfile to multi-stage build --- Dockerfile | 38 ++++++++++++++++---------------------- docker-compose.yml | 2 +- frontend/src/api.js | 2 +- src/app.controller.ts | 9 ++++----- src/main.ts | 4 +--- 5 files changed, 23 insertions(+), 32 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2584282..c7d0fef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,27 @@ -# Step 1: Build Phase | مرحلة البناء -FROM node:20-alpine AS builder - -WORKDIR /usr/src/app - -# Copy package files | نسخ ملفات الحزم -COPY package*.json ./ - -# Install dependencies | تثبيت الاعتماديات +# Step 1: Build Frontend | مرحلة بناء الواجهة +FROM node:20-alpine AS frontend-builder +WORKDIR /usr/src/app/frontend +COPY frontend/package*.json ./ RUN npm install - -# Copy source code | نسخ كود المصدر -COPY . . - -# Build the app | بناء التطبيق +COPY frontend/ ./ RUN npm run build -# Step 2: Production Phase | مرحلة الإنتاج -FROM node:20-alpine - +# Step 2: Build Backend | مرحلة بناء الخلفية +FROM node:20-alpine AS builder WORKDIR /usr/src/app - -# Copy package files | نسخ ملفات الحزم COPY package*.json ./ +RUN npm install +COPY . . +RUN npm run build -# Install only production dependencies | تثبيت اعتماديات الإنتاج فقط +# Step 3: Production Phase | مرحلة الإنتاج +FROM node:20-alpine +WORKDIR /usr/src/app +COPY package*.json ./ RUN npm install --only=production - -# Copy built files from builder | نسخ الملفات المبنية من مرحلة البناء COPY --from=builder /usr/src/app/dist ./dist +# Copy frontend build to backend public folder | نسخ واجهة المستخدم إلى الملفات العامة +COPY --from=frontend-builder /usr/src/app/frontend/dist ./public # Expose port | فتح المنفذ EXPOSE 3660 diff --git a/docker-compose.yml b/docker-compose.yml index 9394d3a..1e14d09 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,7 +32,7 @@ services: image: redis:alpine container_name: ads-analytics-redis ports: - - "6379:6379" + - "6380:6379" restart: always volumes: diff --git a/frontend/src/api.js b/frontend/src/api.js index c70fdaa..0c01cdd 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -1,6 +1,6 @@ import { auth } from './auth.js'; -export const BASE_URL = 'http://localhost:3001/api'; +export const BASE_URL = '/api'; /** * API Wrapper for SaaS Meta Backend diff --git a/src/app.controller.ts b/src/app.controller.ts index 95116d8..c3cc4ff 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -4,15 +4,14 @@ import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @ApiTags('root') @Controller() export class AppController { - @Get() - @ApiOperation({ summary: 'Welcome to the API | الترحيب بالـ API' }) + @Get('status') + @ApiOperation({ summary: 'API Status | حالة الـ API' }) @ApiResponse({ status: 200, description: 'API is running | الـ API يعمل بنجاح' }) getHello() { return { - message: 'Welcome to Ads Analytics SaaS API', - version: '1.0', - docs: '/api/docs', + message: 'Ads Analytics SaaS API', status: 'active', + docs: '/api/docs', }; } } diff --git a/src/main.ts b/src/main.ts index c8f053e..f2d5df3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,9 +23,7 @@ async function bootstrap() { // Serve Static Assets | تقديم الملفات الثابتة // This allows us to share ad images for analysis - app.useStaticAssets(join(__dirname, '..', 'public'), { - prefix: '/api', - }); + app.useStaticAssets(join(__dirname, '..', 'public')); // Get ConfigService for port | الحصول على خدمة الإعدادات للمنفذ const configService = app.get(ConfigService);