mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-12-01 06:55:45 +01:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 15107cdc63 | |||
| 22266c765b | |||
| a66609a40c | |||
| 87dda38bc3 | |||
| 9de501c7eb | |||
| 5c6a50ddcf | |||
| 017f5fb2e0 |
19
Dockerfile
19
Dockerfile
@@ -49,15 +49,15 @@ COPY frontend/public/ ./public/
|
|||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Production stage
|
# Production stage
|
||||||
FROM node:20-alpine
|
FROM node:20-bookworm
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install PM2 for process management
|
# Install PM2 for process management
|
||||||
RUN npm install -g pm2
|
RUN npm install -g pm2
|
||||||
|
|
||||||
# In der Production Stage, füge diese Zeile hinzu:
|
# Create data directory for SQLite database with proper permissions
|
||||||
ENV DB_PATH=/app/data/schichtplan.db
|
RUN mkdir -p /app/data
|
||||||
|
|
||||||
# Copy backend built files
|
# Copy backend built files
|
||||||
COPY --from=backend-builder /app/backend/package*.json ./
|
COPY --from=backend-builder /app/backend/package*.json ./
|
||||||
@@ -70,10 +70,15 @@ COPY --from=frontend-builder /app/frontend/build/ ./frontend-build/
|
|||||||
# Copy PM2 configuration
|
# Copy PM2 configuration
|
||||||
COPY ecosystem.config.cjs ./
|
COPY ecosystem.config.cjs ./
|
||||||
|
|
||||||
# Create a non-root user
|
# Create a non-root user and group - DEBIAN STYLE
|
||||||
RUN addgroup -g 1001 -S nodejs && \
|
RUN groupadd -g 1001 nodejs && \
|
||||||
adduser -S schichtplan -u 1001 && \
|
useradd -m -u 1001 -s /bin/bash -g nodejs schichtplan && \
|
||||||
chown -R schichtplan:nodejs /app
|
chown -R schichtplan:nodejs /app && \
|
||||||
|
chmod 755 /app && \
|
||||||
|
chmod 775 /app/data
|
||||||
|
|
||||||
|
# Set PM2 to use app directory instead of home directory
|
||||||
|
ENV PM2_HOME=/app/.pm2
|
||||||
|
|
||||||
USER schichtplan
|
USER schichtplan
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// backend/src/server.ts
|
// backend/src/server.ts
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import cors from 'cors';
|
import { fileURLToPath } from 'url';
|
||||||
|
import path from 'path';
|
||||||
import { initializeDatabase } from './scripts/initializeDatabase.js';
|
import { initializeDatabase } from './scripts/initializeDatabase.js';
|
||||||
|
|
||||||
// Route imports
|
// Route imports
|
||||||
@@ -11,13 +12,18 @@ import setupRoutes from './routes/setup.js';
|
|||||||
import scheduledShifts from './routes/scheduledShifts.js';
|
import scheduledShifts from './routes/scheduledShifts.js';
|
||||||
import schedulingRoutes from './routes/scheduling.js';
|
import schedulingRoutes from './routes/scheduling.js';
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 3002;
|
const PORT = 3002;
|
||||||
|
|
||||||
// CORS und Middleware
|
// Middleware
|
||||||
app.use(cors());
|
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
|
// Serviere statische Frontend-Dateien
|
||||||
|
app.use(express.static(path.join(__dirname, '../../frontend-build')));
|
||||||
|
|
||||||
// API Routes
|
// API Routes
|
||||||
app.use('/api/setup', setupRoutes);
|
app.use('/api/setup', setupRoutes);
|
||||||
app.use('/api/auth', authRoutes);
|
app.use('/api/auth', authRoutes);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
apps: [
|
apps: [
|
||||||
{
|
{
|
||||||
name: 'backend',
|
name: 'schichtplaner',
|
||||||
script: './dist/server.js',
|
script: './dist/server.js',
|
||||||
instances: 1,
|
instances: 1,
|
||||||
exec_mode: 'fork',
|
exec_mode: 'fork',
|
||||||
@@ -10,21 +10,8 @@ module.exports = {
|
|||||||
NODE_ENV: 'production',
|
NODE_ENV: 'production',
|
||||||
PORT: 3002
|
PORT: 3002
|
||||||
},
|
},
|
||||||
error_file: './logs/backend-err.log',
|
error_file: './logs/app-err.log',
|
||||||
out_file: './logs/backend-out.log',
|
out_file: './logs/app-out.log',
|
||||||
time: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'frontend',
|
|
||||||
script: 'npx',
|
|
||||||
args: 'serve -s frontend-build -l 3000',
|
|
||||||
instances: 1,
|
|
||||||
exec_mode: 'fork',
|
|
||||||
env: {
|
|
||||||
NODE_ENV: 'production'
|
|
||||||
},
|
|
||||||
error_file: './logs/frontend-err.log',
|
|
||||||
out_file: './logs/frontend-out.log',
|
|
||||||
time: true
|
time: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ interface AuthContextType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||||
|
const API_BASE_URL = process.env.REACT_APP_API_BASE_URL || 'http://localhost:3002/api';
|
||||||
|
|
||||||
interface AuthProviderProps {
|
interface AuthProviderProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
@@ -48,7 +49,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
|
|||||||
const checkSetupStatus = async (): Promise<void> => {
|
const checkSetupStatus = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
console.log('🔍 Checking setup status...');
|
console.log('🔍 Checking setup status...');
|
||||||
const response = await fetch('http://localhost:3002/api/setup/status');
|
const response = await fetch(`${API_BASE_URL}/setup/status`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Setup status check failed');
|
throw new Error('Setup status check failed');
|
||||||
}
|
}
|
||||||
@@ -72,7 +73,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch('http://localhost:3002/api/auth/me', {
|
const response = await fetch(`${API_BASE_URL}/auth/me`, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${token}`
|
'Authorization': `Bearer ${token}`
|
||||||
}
|
}
|
||||||
@@ -104,7 +105,7 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
|
|||||||
try {
|
try {
|
||||||
console.log('🔐 Attempting login for:', credentials.email);
|
console.log('🔐 Attempting login for:', credentials.email);
|
||||||
|
|
||||||
const response = await fetch('http://localhost:3002/api/auth/login', {
|
const response = await fetch(`${API_BASE_URL}/auth/login`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// frontend/src/services/authService.ts
|
// frontend/src/services/authService.ts
|
||||||
import { Employee } from '../models/Employee';
|
import { Employee } from '../models/Employee';
|
||||||
const API_BASE = 'http://localhost:3002/api';
|
const API_BASE = process.env.REACT_APP_API_BASE_URL || 'http://localhost:3002/api';
|
||||||
|
|
||||||
export interface LoginRequest {
|
export interface LoginRequest {
|
||||||
email: string;
|
email: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user