From 0c12daf8d2409b945f6fb0abdce20c6123a83c2c Mon Sep 17 00:00:00 2001 From: giteaAdmin Date: Wed, 25 Jun 2025 14:11:13 +0000 Subject: [PATCH] Upload files to "/" --- .env.example | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ .env.production | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ config.json | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 17 +++++++++++++++++ 5 files changed, 210 insertions(+) create mode 100644 .env.example create mode 100644 .env.production create mode 100644 Dockerfile create mode 100644 config.json create mode 100644 package.json diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..1211e34 --- /dev/null +++ b/.env.example @@ -0,0 +1,48 @@ +PORT=3001 +API_KEY=your-secure-api-key-here +NODE_ENV=development +API_ROOT_DIRECTORY=/ + +# Server Configuration +SERVER_NAME=File Manager API Server +SERVER_VERSION=1.0.0 + +# File Transfer Settings +MAX_FILE_SIZE=104857600 +MAX_CONCURRENT_TRANSFERS=5 +UPLOAD_TIMEOUT=300000 + +# File System Settings +FS_CACHE_TTL=60000 +FS_MAX_DEPTH=10 +FS_WATCH_ENABLED=true + +# Security Settings +CORS_ORIGIN=http://localhost:3000,http://localhost:5173 +REQUEST_TIMEOUT=30000 +MAX_REQUEST_SIZE=104857600 + +# Logging Configuration +LOG_LEVEL=info +LOG_REQUESTS=true +LOG_ERRORS=true +LOG_FILE_PATH=./logs/api-server.log + +# Rate Limiting +RATE_LIMIT_WINDOW=900000 +RATE_LIMIT_MAX_REQUESTS=1000 + +# Health Check Settings +HEALTH_CHECK_ENABLED=true +HEALTH_CHECK_INTERVAL=60000 + +# Database Settings (if needed in future) +# DB_HOST=localhost +# DB_PORT=5432 +# DB_NAME=filemanager +# DB_USER=filemanager +# DB_PASSWORD=your-db-password + +# External Services (if needed) +# EXTERNAL_API_URL=https://api.example.com +# EXTERNAL_API_KEY=your-external-api-key \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..75299c6 --- /dev/null +++ b/.env.production @@ -0,0 +1,48 @@ +# API Server Production Environment Variables +PORT=3001 +API_KEY=your-secure-api-key-here +NODE_ENV=production +API_ROOT_DIRECTORY=/app/data + +# Server Configuration +SERVER_NAME=File Manager API Server +SERVER_VERSION=1.0.0 + +# File Transfer Settings +MAX_FILE_SIZE=104857600 +MAX_CONCURRENT_TRANSFERS=10 +UPLOAD_TIMEOUT=600000 + +# File System Settings +FS_CACHE_TTL=60000 +FS_MAX_DEPTH=10 +FS_WATCH_ENABLED=true + +# Security Settings - Allow all origins for production flexibility +CORS_ORIGIN=* +REQUEST_TIMEOUT=60000 +MAX_REQUEST_SIZE=104857600 + +# Logging Configuration +LOG_LEVEL=info +LOG_REQUESTS=true +LOG_ERRORS=true +LOG_FILE_PATH=/app/logs/api-server.log + +# Rate Limiting +RATE_LIMIT_WINDOW=900000 +RATE_LIMIT_MAX_REQUESTS=2000 + +# Health Check Settings +HEALTH_CHECK_ENABLED=true +HEALTH_CHECK_INTERVAL=60000 + +# Supabase Configuration (for future database integration) +SUPABASE_URL= +SUPABASE_ANON_KEY= +SUPABASE_SERVICE_ROLE_KEY= +SUPABASE_DB_URL= + +# External Services (if needed) +EXTERNAL_API_URL= +EXTERNAL_API_KEY= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..75595b4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ +# Use Node.js 20 Alpine Linux as base image (small and secure) +FROM node:20-alpine + +# Set working directory +WORKDIR /app + +# Create non-root user for security +RUN addgroup --system --gid 1001 apiserver && \ + adduser --system --uid 1001 --ingroup apiserver apiserver + +# Install curl for health checks +RUN apk add --no-cache curl + +# Copy package files first for better Docker layer caching +COPY package*.json ./ + +# Install dependencies +RUN npm ci --only=production && npm cache clean --force + +# Copy configuration files +COPY config.json ./ +COPY .env.production ./.env + +# Copy server source code +COPY server.js ./ + +# Create necessary directories and set permissions +RUN mkdir -p /app/data /app/logs && \ + chown -R apiserver:apiserver /app + +# Switch to non-root user +USER apiserver + +# Expose port 3001 +EXPOSE 3001 + +# Health check to ensure container stays healthy +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:3001/api/v1/health \ + -H "Authorization: Bearer ${API_KEY:-your-secure-api-key-here}" || exit 1 + +# Set environment variables +ENV NODE_ENV=production +ENV PORT=3001 +ENV API_ROOT_DIRECTORY=/app/data + +# Start the API server +CMD ["node", "server.js"] \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..b75519e --- /dev/null +++ b/config.json @@ -0,0 +1,49 @@ +{ + "server": { + "name": "File Manager API Server", + "port": 3001, + "rootDirectory": "/", + "logLevel": "info", + "environment": "development", + "capabilities": [ + "file-transfer", + "server-management", + "health-monitoring", + "filesystem-browsing" + ] + }, + "filesystem": { + "maxDepth": 10, + "cacheSettings": { + "ttl": 60000, + "refreshInterval": 300000 + }, + "watchEnabled": true, + "maxFileSize": 104857600 + }, + "transfer": { + "maxConcurrentTransfers": 5, + "uploadTimeout": 300000, + "maxRequestSize": 104857600 + }, + "security": { + "corsOrigins": [ + "http://localhost:3000", + "http://localhost:5173" + ], + "requestTimeout": 30000, + "rateLimiting": { + "windowMs": 900000, + "maxRequests": 1000 + } + }, + "logging": { + "requests": true, + "errors": true, + "filePath": "./logs/api-server.log" + }, + "health": { + "checkEnabled": true, + "checkInterval": 60000 + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..6b7820f --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "file-manager-api-server", + "version": "1.0.0", + "description": "API Server for File Manager", + "main": "server.js", + "type": "module", + "scripts": { + "start": "node server.js", + "dev": "node --watch server.js" + }, + "dependencies": { + "express": "^4.18.2", + "cors": "^2.8.5", + "dotenv": "^16.3.1", + "crypto": "^1.0.1" + } +} \ No newline at end of file