fix: Prevent nodemon restarts during policy creation

- Move temp directory outside app folder to /tmp/minio-webui-temp
- Add nodemon.json to ignore temp, logs, and node_modules
- Add TEMP_DIR environment variable configuration
- Add cleanup routine for old temporary policy files (>1 hour)
- Update both dev and production Dockerfiles
- Update docker-compose configurations

This fixes the 500 error during QuickStartWizard policy creation
caused by nodemon restarting when temporary files were created.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-07-24 09:35:03 +02:00
parent 9cdd7b0050
commit 93d9c47ad5
6 changed files with 45 additions and 6 deletions
+1
View File
@@ -2,6 +2,7 @@
NODE_ENV=production NODE_ENV=production
PORT=7510 PORT=7510
LOG_LEVEL=info LOG_LEVEL=info
TEMP_DIR=/tmp/minio-webui-temp
# Authentication # Authentication
ADMIN_PASSWORD_HASH=$2b$12$REPLACE_WITH_ACTUAL_HASH ADMIN_PASSWORD_HASH=$2b$12$REPLACE_WITH_ACTUAL_HASH
+14
View File
@@ -0,0 +1,14 @@
{
"watch": ["src"],
"ext": "js,json",
"ignore": [
"src/**/*.spec.js",
"node_modules",
"logs",
"temp",
"*.log",
"*.tmp",
"*.temp"
],
"delay": "1000"
}
+23
View File
@@ -19,11 +19,34 @@ class MinIOService {
async ensureTempDir() { async ensureTempDir() {
try { try {
await fs.mkdir(this.tempDir, { recursive: true }); await fs.mkdir(this.tempDir, { recursive: true });
// Clean up old temp files (older than 1 hour)
this.cleanupTempFiles();
} catch (error) { } catch (error) {
logger.error('Failed to create temp directory:', error); logger.error('Failed to create temp directory:', error);
} }
} }
async cleanupTempFiles() {
try {
const files = await fs.readdir(this.tempDir);
const now = Date.now();
const oneHour = 60 * 60 * 1000;
for (const file of files) {
if (file.endsWith('.json')) {
const filePath = path.join(this.tempDir, file);
const stats = await fs.stat(filePath);
if (now - stats.mtimeMs > oneHour) {
await fs.unlink(filePath);
logger.debug(`Cleaned up old temp file: ${file}`);
}
}
}
} catch (error) {
logger.debug('Error cleaning temp files:', error);
}
}
// Execute MinIO CLI command with timeout and error handling // Execute MinIO CLI command with timeout and error handling
async executeCommand(command, options = {}) { async executeCommand(command, options = {}) {
const { timeout = 30000, parseJson = false } = options; const { timeout = 30000, parseJson = false } = options;
+2 -2
View File
@@ -13,7 +13,7 @@ services:
NODE_ENV: development NODE_ENV: development
PORT: 7510 PORT: 7510
LOG_DIR: /app/logs LOG_DIR: /app/logs
TEMP_DIR: /app/temp TEMP_DIR: /tmp/minio-webui-temp
LOG_LEVEL: debug LOG_LEVEL: debug
env_file: env_file:
- .env - .env
@@ -24,7 +24,7 @@ services:
- ./backend/package.json:/app/package.json - ./backend/package.json:/app/package.json
- ./backend/package-lock.json:/app/package-lock.json - ./backend/package-lock.json:/app/package-lock.json
- backend-logs:/app/logs - backend-logs:/app/logs
- backend-temp:/app/temp - backend-temp:/tmp/minio-webui-temp
- mc-config:/home/node/.mc - mc-config:/home/node/.mc
depends_on: depends_on:
- redis - redis
+3 -2
View File
@@ -30,9 +30,10 @@ RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 adduser -S nodejs -u 1001
# Create necessary directories with proper permissions # Create necessary directories with proper permissions
RUN mkdir -p logs temp && \ RUN mkdir -p logs /tmp/minio-webui-temp && \
chown -R nodejs:nodejs /app && \ chown -R nodejs:nodejs /app && \
chmod 755 logs temp chown nodejs:nodejs /tmp/minio-webui-temp && \
chmod 755 logs /tmp/minio-webui-temp
# Switch to non-root user # Switch to non-root user
USER nodejs USER nodejs
+2 -2
View File
@@ -24,8 +24,8 @@ RUN NODE_ENV=development npm install && \
npm rebuild bcrypt --build-from-source npm rebuild bcrypt --build-from-source
# Create necessary directories # Create necessary directories
RUN mkdir -p logs temp && \ RUN mkdir -p logs /tmp/minio-webui-temp && \
chmod 755 logs temp chmod 755 logs /tmp/minio-webui-temp
# Copy application files # Copy application files
COPY . . COPY . .