Overview
Kontrak Backend uses environment variables for configuration. All settings are loaded from a.env file and accessed through a centralized configuration module.
Environment Variables
Server Configuration
Application environment. Set to
production for production deployments.Port number where the server will listen for requests.
Hostname for the server. Use
0.0.0.0 to accept connections from any network interface.CORS Configuration
Comma-separated list of allowed origins for CORS requests.Example:
The CORS middleware will log blocked origins to help you debug access issues. Check your server logs if you’re experiencing CORS errors.
File Limits
Maximum file size in bytes. Default is 10MB (10485760 bytes).
Maximum number of employees that can be processed in a single batch operation.
Directories
Directory path for storing temporary files during contract generation.
Timeouts & Cleanup
Timeout in milliseconds before temporary files are cleaned up. Default is 1 hour (3600000ms).
Configuration File Structure
The configuration is centralized insrc/config/index.ts:
Setting Up Your Environment
CORS Setup Details
The CORS configuration (src/config/cors.config.ts) supports:
- Dynamic origin validation: Only whitelisted origins are allowed
- Logging: Blocked origins are logged for debugging
- HTTP Methods: GET, POST, PUT, DELETE, PATCH
Production Settings
Recommended Production Configuration
Security Considerations
CORS Origins
CORS Origins
- Never use wildcards (
*) in production - Only whitelist domains you own and control
- Include all subdomains that need access
- Use HTTPS URLs in production
File Size Limits
File Size Limits
- Set
MAX_FILE_SIZEbased on your server capacity - Too large files can cause memory issues
- Consider implementing virus scanning for uploaded files
Temporary Files
Temporary Files
- Ensure
TEMP_DIRhas adequate disk space - Configure
FILE_CLEANUP_TIMEOUTto prevent disk filling - Consider using a separate partition for temp files
- Implement monitoring for disk usage
Environment Variables
Environment Variables
- Never commit
.envfiles to version control - Use secret management systems in production
- Rotate sensitive credentials regularly
- Validate all environment variables on startup
Validating Configuration
The application validates critical configuration on startup:Troubleshooting
Port Already in Use
If you get anEADDRINUSE error:
CORS Errors
Check server logs for blocked origins:CORS_ORIGINS.
File Upload Errors
If files fail to upload:- Check
MAX_FILE_SIZEsetting - Verify
TEMP_DIRexists and is writable - Ensure sufficient disk space
Configuration Not Loading
- Verify
.envfile is in the project root - Check for syntax errors in
.env - Restart the server after changes
- Review startup logs for configuration warnings
Next Steps
Generating Contracts
Learn how to generate employment contracts
Excel Upload
Understand Excel file format requirements