svalavuo 2 dienas atpakaļ
vecāks
revīzija
1e161d5a9f

+ 78 - 0
Dockerfile.unified

@@ -0,0 +1,78 @@
+# Multi-stage build for unified backend + frontend container
+FROM node:18-alpine AS frontend-build
+
+# Set working directory for frontend build
+WORKDIR /app/frontend
+
+# Copy frontend package files
+COPY frontend/package*.json ./
+
+# Install frontend dependencies
+RUN npm ci --only=production
+
+# Copy frontend source code
+COPY frontend/ ./
+
+# Build frontend for production
+RUN npm run build
+
+# Backend + Frontend unified container
+FROM php:8.1-apache
+
+# Install system dependencies and PHP extensions
+RUN apt-get update && apt-get install -y \
+    libzip-dev \
+    libpng-dev \
+    libjpeg-dev \
+    libfreetype6-dev \
+    zip \
+    unzip \
+    curl \
+    && docker-php-ext-configure gd --with-freetype --with-jpeg \
+    && docker-php-ext-install gd zip pdo_mysql \
+    && a2enmod rewrite \
+    && a2enmod headers
+
+# Install Composer
+COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
+
+# Set working directory for backend
+WORKDIR /var/www/html
+
+# Copy backend source code
+COPY backend/ ./
+
+# Install backend dependencies
+RUN composer install --no-dev --optimize-autoloader
+
+# Create api directory and copy backend files there
+RUN mkdir -p api && cp -r *.php api/ && cp -r models api/ && cp -r vendor api/ && cp composer.json api/ && cp -r config api/ && cp -r middleware api/ && cp -r database api/
+
+# Copy built frontend files directly to root
+COPY --from=frontend-build /app/frontend/dist ./
+
+# Create uploads directory and set permissions
+RUN mkdir -p uploads && chmod -R 755 uploads
+
+# Copy Apache configuration
+COPY docker/apache.conf /etc/apache2/sites-available/000-default.conf
+
+# Copy custom Apache configuration for unified setup
+COPY docker/apache-unified-simple.conf /etc/apache2/sites-available/unified.conf
+
+# Enable the unified site
+RUN a2ensite unified.conf && a2dissite 000-default.conf
+
+# Set environment variables for frontend build
+ARG VUE_APP_API_URL=/api
+ENV VUE_APP_API_URL=/api
+
+# Expose port 80
+EXPOSE 80
+
+# Health check
+HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
+    CMD curl -f http://localhost/api/company.php || exit 1
+
+# Start Apache
+CMD ["apache2-foreground"]

+ 76 - 0
Dockerfile.unified-working

@@ -0,0 +1,76 @@
+# Multi-stage build for unified backend + frontend container
+FROM node:18-alpine AS frontend-build
+
+# Set working directory for frontend build
+WORKDIR /app/frontend
+
+# Copy frontend package files
+COPY frontend/package*.json ./
+
+# Install frontend dependencies
+RUN npm ci --only=production
+
+# Copy frontend source code
+COPY frontend/ ./
+
+# Build frontend for production
+RUN npm run build && ls -la dist/
+
+# Backend + Frontend unified container
+FROM php:8.1-apache
+
+# Install system dependencies and PHP extensions
+RUN apt-get update && apt-get install -y \
+    libzip-dev \
+    libpng-dev \
+    libjpeg-dev \
+    libfreetype6-dev \
+    zip \
+    unzip \
+    curl \
+    && docker-php-ext-configure gd --with-freetype --with-jpeg \
+    && docker-php-ext-install gd zip pdo_mysql \
+    && a2enmod rewrite \
+    && a2enmod headers
+
+# Install Composer
+COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
+
+# Set working directory for backend
+WORKDIR /var/www/html
+
+# Copy backend source code
+COPY backend/ ./
+
+# Install backend dependencies
+RUN composer install --no-dev --optimize-autoloader
+
+# Create api directory and copy backend files there
+RUN mkdir -p api && cp -r *.php api/ && cp -r models api/ && cp -r vendor api/ && cp composer.json api/ && cp -r config api/ && cp -r middleware api/ && cp -r database api/
+
+# Copy built frontend files to frontend/dist directory
+RUN mkdir -p frontend/dist
+COPY --from=frontend-build /app/frontend/dist/ ./frontend/dist/
+
+# Create uploads directory and set permissions
+RUN mkdir -p uploads && chmod -R 755 uploads
+
+# Copy Apache configuration
+COPY docker/apache-unified-simple.conf /etc/apache2/sites-available/unified.conf
+
+# Enable the unified site
+RUN a2ensite unified.conf && a2dissite 000-default.conf
+
+# Set environment variables for frontend build
+ARG VUE_APP_API_URL=/api
+ENV VUE_APP_API_URL=/api
+
+# Expose port 80
+EXPOSE 80
+
+# Health check
+HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
+    CMD curl -f http://localhost/api/company.php || exit 1
+
+# Start Apache
+CMD ["apache2-foreground"]

+ 86 - 0
docker-compose.unified.prod.yml

@@ -0,0 +1,86 @@
+version: '3.8'
+
+services:
+  # Unified Backend + Frontend Application (Production)
+  app:
+    build:
+      context: .
+      dockerfile: Dockerfile.unified
+      args:
+        - VUE_APP_API_URL=/api
+    container_name: inventory-app-prod
+    ports:
+      - "${FRONTEND_PORT:-3000}:80"
+    environment:
+      # Database Configuration
+      - DB_HOST=${DB_HOST:-127.0.0.1}
+      - DB_PORT=${DB_PORT:-3306}
+      - DB_NAME=${DB_NAME:-inventory_db}
+      - DB_USER=${DB_USER:-root}
+      - DB_PASS=${DB_PASS:-root}
+      
+      # Company Information
+      - COMPANY_NAME=${COMPANY_NAME:-Your Company Name}
+      - COMPANY_ADDRESS=${COMPANY_ADDRESS:-123 Business Street}
+      - COMPANY_POSTAL_CODE=${COMPANY_POSTAL_CODE:-00100}
+      - COMPANY_CITY=${COMPANY_CITY:-Helsinki}
+      - COMPANY_COUNTRY=${COMPANY_COUNTRY:-Finland}
+      - COMPANY_PHONE=${COMPANY_PHONE:-+358 123 456 789}
+      - COMPANY_EMAIL=${COMPANY_EMAIL:-info@company.com}
+      - COMPANY_Y_TUNNUS=${COMPANY_Y_TUNNUS:-1234567-8}
+      
+      # File Upload Configuration
+      - UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE:-10M}
+      - ALLOWED_FILE_TYPES=${ALLOWED_FILE_TYPES:-pdf,doc,docx,xls,xlsx,jpg,jpeg,png,gif}
+      - UPLOADS_PATH=${UPLOADS_PATH:-./uploads}
+      
+      # Frontend Configuration (relative path for internal communication)
+      - VUE_APP_API_URL=/api
+      
+      # Optional: Redis Configuration
+      - REDIS_HOST=${REDIS_HOST:-redis}
+      - REDIS_PORT=${REDIS_PORT:-6379}
+      
+      # Optional: Email Configuration (for future use)
+      - MAIL_HOST=${MAIL_HOST:-smtp.gmail.com}
+      - MAIL_PORT=${MAIL_PORT:-587}
+      - MAIL_USERNAME=${MAIL_USERNAME:-your-email@gmail.com}
+      - MAIL_PASSWORD=${MAIL_PASSWORD:-your-app-password}
+    
+    volumes:
+      - ./uploads:/var/www/html/uploads
+      - ./backend:/var/www/html
+    networks:
+      - inventory-network
+    restart: unless-stopped
+    healthcheck:
+      test: ["CMD", "curl", "-f", "http://localhost/api/company.php"]
+      interval: 30s
+      timeout: 10s
+      retries: 3
+      start_period: 40s
+
+  # Redis Service (optional)
+  redis:
+    image: redis:7-alpine
+    container_name: inventory-redis-prod
+    ports:
+      - "${REDIS_PORT:-6379}:6379"
+    volumes:
+      - redis_data:/data
+    networks:
+      - inventory-network
+    restart: unless-stopped
+    command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
+
+# Networks
+networks:
+  inventory-network:
+    driver: bridge
+
+# Volumes
+volumes:
+  uploads_data:
+    driver: local
+  redis_data:
+    driver: local

+ 86 - 0
docker-compose.unified.yml

@@ -0,0 +1,86 @@
+version: '3.8'
+
+services:
+  # Unified Backend + Frontend Application
+  app:
+    build:
+      context: .
+      dockerfile: Dockerfile.unified-working
+      args:
+        - VUE_APP_API_URL=/api
+    container_name: inventory-app
+    ports:
+      - "${FRONTEND_PORT:-3000}:80"
+    environment:
+      # Database Configuration
+      - DB_HOST=${DB_HOST:-127.0.0.1}
+      - DB_PORT=${DB_PORT:-3306}
+      - DB_NAME=${DB_NAME:-inventory_db}
+      - DB_USER=${DB_USER:-root}
+      - DB_PASS=${DB_PASS:-root}
+      
+      # Company Information
+      - COMPANY_NAME=${COMPANY_NAME:-Your Company Name}
+      - COMPANY_ADDRESS=${COMPANY_ADDRESS:-123 Business Street}
+      - COMPANY_POSTAL_CODE=${COMPANY_POSTAL_CODE:-00100}
+      - COMPANY_CITY=${COMPANY_CITY:-Helsinki}
+      - COMPANY_COUNTRY=${COMPANY_COUNTRY:-Finland}
+      - COMPANY_PHONE=${COMPANY_PHONE:-+358 123 456 789}
+      - COMPANY_EMAIL=${COMPANY_EMAIL:-info@company.com}
+      - COMPANY_Y_TUNNUS=${COMPANY_Y_TUNNUS:-1234567-8}
+      
+      # File Upload Configuration
+      - UPLOAD_MAX_SIZE=${UPLOAD_MAX_SIZE:-10M}
+      - ALLOWED_FILE_TYPES=${ALLOWED_FILE_TYPES:-pdf,doc,docx,xls,xlsx,jpg,jpeg,png,gif}
+      - UPLOADS_PATH=${UPLOADS_PATH:-./uploads}
+      
+      # Frontend Configuration (relative path for internal communication)
+      - VUE_APP_API_URL=/api
+      
+      # Optional: Redis Configuration
+      - REDIS_HOST=${REDIS_HOST:-redis}
+      - REDIS_PORT=${REDIS_PORT:-6379}
+      
+      # Optional: Email Configuration (for future use)
+      - MAIL_HOST=${MAIL_HOST:-smtp.gmail.com}
+      - MAIL_PORT=${MAIL_PORT:-587}
+      - MAIL_USERNAME=${MAIL_USERNAME:-your-email@gmail.com}
+      - MAIL_PASSWORD=${MAIL_PASSWORD:-your-app-password}
+    
+    volumes:
+      - ./uploads:/var/www/html/uploads
+      - ./backend:/var/www/html
+    networks:
+      - inventory-network
+    restart: unless-stopped
+    healthcheck:
+      test: ["CMD", "curl", "-f", "http://localhost/api/company.php"]
+      interval: 30s
+      timeout: 10s
+      retries: 3
+      start_period: 40s
+
+  # Redis Service (optional)
+  redis:
+    image: redis:7-alpine
+    container_name: inventory-redis
+    ports:
+      - "${REDIS_PORT:-6379}:6379"
+    volumes:
+      - redis_data:/data
+    networks:
+      - inventory-network
+    restart: unless-stopped
+    command: redis-server --appendonly yes
+
+# Networks
+networks:
+  inventory-network:
+    driver: bridge
+
+# Volumes
+volumes:
+  uploads_data:
+    driver: local
+  redis_data:
+    driver: local

+ 68 - 0
docker/apache-unified-simple.conf

@@ -0,0 +1,68 @@
+<VirtualHost *:80>
+    ServerName inventory.local
+    DocumentRoot /var/www/html/frontend/dist
+    
+    # Enable CORS headers for API requests
+    Header always set Access-Control-Allow-Origin "*"
+    Header always set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
+    Header always set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With"
+    Header always set Access-Control-Allow-Credentials "true"
+    
+    # Handle preflight requests
+    RewriteEngine On
+    RewriteCond %{REQUEST_METHOD} OPTIONS
+    RewriteRule ^(.*)$ $1 [R=200,L]
+    
+    # API routes - handle PHP files in api directory
+    <Directory "/var/www/html/api">
+        Options -Indexes +FollowSymLinks
+        AllowOverride All
+        Require all granted
+        
+        # Handle PHP files
+        <FilesMatch "\.php$">
+            SetHandler application/x-httpd-php
+        </FilesMatch>
+    </Directory>
+    
+    # Root directory - serve frontend files and handle PHP
+    <Directory "/var/www/html">
+        Options -Indexes +FollowSymLinks
+        AllowOverride All
+        Require all granted
+        
+        # Handle PHP files
+        <FilesMatch "\.php$">
+            SetHandler application/x-httpd-php
+        </FilesMatch>
+        
+        # Vue.js SPA routing - fallback to index.html for non-API, non-PHP requests
+        RewriteEngine On
+        RewriteBase /
+        
+        # Don't rewrite API requests
+        RewriteCond %{REQUEST_URI} ^/api/
+        RewriteRule ^ - [L]
+        
+        # Don't rewrite PHP files
+        RewriteCond %{REQUEST_URI} \.php$
+        RewriteRule ^ - [L]
+        
+        # Don't rewrite existing files/directories
+        RewriteCond %{REQUEST_FILENAME} -f [OR]
+        RewriteCond %{REQUEST_FILENAME} -d
+        RewriteRule ^ - [L]
+        
+        # Fallback to index.html for Vue.js SPA
+        RewriteRule . index.html [L]
+    </Directory>
+    
+    # Security headers
+    Header always set X-Content-Type-Options nosniff
+    Header always set X-Frame-Options DENY
+    Header always set X-XSS-Protection "1; mode=block"
+    
+    # Error handling
+    ErrorLog ${APACHE_LOG_DIR}/error.log
+    CustomLog ${APACHE_LOG_DIR}/access.log combined
+</VirtualHost>

+ 66 - 0
docker/apache-unified.conf

@@ -0,0 +1,66 @@
+<VirtualHost *:80>
+    ServerName inventory.local
+    DocumentRoot /var/www/html/frontend/dist
+    
+    # Enable CORS headers for API requests
+    Header always set Access-Control-Allow-Origin "*"
+    Header always set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
+    Header always set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With"
+    Header always set Access-Control-Allow-Credentials "true"
+    
+    # Handle preflight requests
+    RewriteEngine On
+    RewriteCond %{REQUEST_METHOD} OPTIONS
+    RewriteRule ^(.*)$ $1 [R=200,L]
+    
+    # API routes - redirect to PHP backend
+    Alias /api /var/www/html/api
+    
+    # Static files and frontend routes
+    <Directory "/var/www/html/frontend/dist">
+        Options -Indexes +FollowSymLinks
+        AllowOverride All
+        Require all granted
+        
+        # Vue.js SPA routing - fallback to index.html
+        RewriteEngine On
+        RewriteBase /
+        RewriteRule ^index\.html$ - [L]
+        RewriteCond %{REQUEST_FILENAME} !-f
+        RewriteCond %{REQUEST_FILENAME} !-d
+        RewriteRule . /index.html [L]
+    </Directory>
+    
+    # PHP backend directory
+    <Directory "/var/www/html">
+        Options -Indexes +FollowSymLinks
+        AllowOverride All
+        Require all granted
+        
+        # Handle PHP files
+        <FilesMatch "\.php$">
+            SetHandler application/x-httpd-php
+        </FilesMatch>
+    </Directory>
+    
+    # API directory
+    <Directory "/var/www/html/api">
+        Options -Indexes +FollowSymLinks
+        AllowOverride All
+        Require all granted
+        
+        # Handle PHP files
+        <FilesMatch "\.php$">
+            SetHandler application/x-httpd-php
+        </FilesMatch>
+    </Directory>
+    
+    # Security headers
+    Header always set X-Content-Type-Options nosniff
+    Header always set X-Frame-Options DENY
+    Header always set X-XSS-Protection "1; mode=block"
+    
+    # Error handling
+    ErrorLog ${APACHE_LOG_DIR}/error.log
+    CustomLog ${APACHE_LOG_DIR}/access.log combined
+</VirtualHost>

+ 1 - 1
frontend/.env.production

@@ -1,4 +1,4 @@
 # Production environment variables for Vue.js frontend
-VUE_APP_API_URL=http://localhost:9123
+VUE_APP_API_URL=/api
 VUE_APP_TITLE=Inventory Management System
 VUE_APP_VERSION=1.0.0

+ 1 - 1
frontend/src/api/axios.js

@@ -2,7 +2,7 @@ import axios from 'axios'
 
 // Create axios instance with base URL
 const api = axios.create({
-  baseURL: import.meta.env.VUE_APP_API_URL || 'http://localhost:8080',
+  baseURL: import.meta.env.VUE_APP_API_URL || '/api',
   timeout: 10000,
   headers: {
     'Content-Type': 'application/json'