Upload files to "/"

This commit is contained in:
2025-06-25 14:11:13 +00:00
commit 0c12daf8d2
5 changed files with 210 additions and 0 deletions

48
.env.example Normal file
View File

@ -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

48
.env.production Normal file
View File

@ -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=

48
Dockerfile Normal file
View File

@ -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"]

49
config.json Normal file
View File

@ -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
}
}

17
package.json Normal file
View File

@ -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"
}
}