This section explains how to configure and run the application using environment variables. The application uses
structured configuration via the ApplicationEnv
struct, which is divided into application-level and database-level
settings.
The application reads its configuration from the following environment variables:
Variable | Description | Default Value | Required? |
---|---|---|---|
API_SECRET_AUTHORIZATION |
Secret used to encrypt and decrypt API token claims. | N/A | Yes |
API_SECRET_KEY |
The api private key used for API security. Used to generate and validate if client is authorization to access the api. | N/A | Yes |
PORT |
The port on which the application runs. | 1080 |
No |
CONTEXT_PATH |
The base path used for API routing. | /api/private-network/v1/ |
No |
PEERS_RESOURCE_PATH |
Filesystem path for peer resource connections. | /etc/wireguard/ |
No |
API_INIT_FILE |
Add the first user data that will be created at the application startup | N/A | No |
DEBUG_MODE |
Set log.SetFlags(log.LstdFlags | log.Llongfile) |
N/A | No |
Variable | Description | Required? |
---|---|---|
MONGO_DATABASE |
Name of the MongoDB database the application connects to. | Yes |
MONGO_USERNAME |
Username for MongoDB authentication. | Yes |
MONGO_PASSWORD |
Password for MongoDB authentication. | Yes |
MONGO_URI |
MongoDB connection URI. | Yes |
- The default server port is
1080
ifPORT
is not specified. - The default API context path is
/api/private-network/v1/
ifCONTEXT_PATH
is not provided. - The default path for peer resources is
/etc/wireguard/
ifPEERS_RESOURCE_PATH
is not provided.
Here is an example .env
file for setting up the environment variables:
# Server Configuration
API_SECRET_AUTHORIZATION=my-secret-for-auth
API_SECRET_KEY=my-api-secret-key
PORT=3000
CONTEXT_PATH=/custom/api/path/
PEERS_RESOURCE_PATH=/config/peers/
# Database Configuration
MONGO_DATABASE=my-app-database
MONGO_USERNAME=my-db-user
MONGO_PASSWORD=my-db-password
MONGO_URI=mongodb://localhost:27017
- Note: The following commands assume you have Docker installed on your machine and use the
./dev/.env
file that is not recommended for production.
make compile
- Check the
./dev/.env
file for the environment variables
make rebuild ENV=<< .env file path >>
- Run a demo application
make compile && make up
The application initializes by loading environment variables during startup. Here’s how the variables work:
-
General Configuration:
- Variables such as
API_SECRET_AUTHORIZATION
andAPI_SECRET_KEY
are essential for securing API operations. - Optional fields like
PORT
andCONTEXT_PATH
fallback to default values if not provided.
- Variables such as
-
Database Configuration:
- All
MONGO_*
variables (e.g., database name, URI, username, and password) are required to establish a successful MongoDB connection. - If a variable is missing, application startup will likely fail.
- All
- Sensitive Variables: Avoid committing sensitive information (e.g., secrets, API keys, passwords) to version
control. Use tools like
.env
files (local development) or secret management systems (production). - Default Paths: Make sure the paths, such as
PEERS_RESOURCE_PATH
, align with your intended filesystem structure in production environments. - Error Handling: Ensure you have runtime checks for missing or misconfigured environment variables to prevent application crashes.
This documentation is concise, yet it contains all the necessary details for configuring and running the application. Let me know if you need further adjustments!