Overview
The server configuration controls how the MTB Backend API listens for incoming requests and manages application security. Configuration is defined inconfig/server.ts and controlled through environment variables.
Server Settings
Host and Port
The hostname or IP address the server will bind to. Use
0.0.0.0 to listen on all network interfaces, or 127.0.0.1 for localhost only.The port number the server will listen on for HTTP requests.
In production environments, it’s common to use
0.0.0.0 as the host to allow the server to accept connections from any network interface. A reverse proxy like NGINX typically handles external traffic.Application Keys
Security Keys
Array of secret keys used for signing and encrypting sessions, cookies, and other security-sensitive data. Required for production deployments.
Generating App Keys
App keys should be long, random strings. You can generate them using various methods:Setting App Keys
Provide multiple keys as a comma-separated list in your.env file:
.env
Multiple keys enable key rotation. The first key is used for signing new data, while the others are used to validate existing signatures during rotation periods.
Configuration Example
Environment-Specific Configuration
Development
For local development:.env
Staging
For staging environments:.env
Production
For production deployments:.env
Deployment Considerations
Reverse Proxy Setup
When deploying behind a reverse proxy (NGINX, Apache, etc.):.env
localhost:1337.
Container Deployment
For Docker or containerized deployments:.env
Docker
Port Binding
Ports below 1024 typically require root privileges on Unix-like systems. Consider using a reverse proxy or port forwarding instead of binding directly to ports like 80 or 443.
Troubleshooting
Server Won’t Start
If the server fails to start:-
Check if the port is already in use:
-
Verify APP_KEYS is set:
-
Check host binding permissions:
- Use
127.0.0.1for localhost testing - Ensure you have permission to bind to the specified interface
- Use
Cannot Connect to Server
If you cannot connect to the server:-
Verify the server is running:
-
Check firewall rules:
- Ensure the port is not blocked
- Verify network security groups (cloud deployments)
-
Confirm host binding:
127.0.0.1only accepts localhost connections0.0.0.0accepts connections from any interface
