Configuring the server through an environment file
Batman wanted to configure the server through an environment file. Changing code continuously induced the risk of error.
Environment Variables
ROBYN_PORT
: Specifies the port on which the Robyn server will listen.- Default:
8080
- Example:
ROBYN_PORT=3000
- Default:
ROBYN_HOST
: Specifies the host address for the Robyn server.- Default:
127.0.0.1
- Example:
ROBYN_HOST=0.0.0.0
- Default:
ROBYN_BROWSER_OPEN
: Open the browser on successful start.- Default:
False
- Example:
ROBYN_BROWSER_OPEN=True
- Default:
ROBYN_DEV_MODE
: Configures the dev mode- Default:
False
- Example:
ROBYN_DEV_MODE=True
- Default:
ROBYN_MAX_PAYLOAD_SIZE
: Sets the maximum payload size for requests in bytes.- Default:
1000000
bytes - Example:
ROBYN_MAX_PAYLOAD_SIZE=1000000
- Default:
You can have a robyn.env
file to load them automatically in your environment.
These environment variables are typically set in a robyn.env
file located at the root of the project. The server parses this file at startup to configure itself accordingly.
For more details on the structure and usage of the robyn.env
file, refer to the documentation snippet:
Sample project directory
--project/
--robyn.env
--index.py
...
Sample robyn.env
file:
Sample Robyn.env
ROBYN_PORT=8080
ROBYN_HOST=127.0.0.1
RANDOM_ENV=123
ROBYN_BROWSER_OPEN=True
ROBYN_DEV_MODE=True
ROBYN_MAX_PAYLOAD_SIZE=1000000
With the web application deployed and running smoothly, Batman had a powerful new tool at his disposal. The Robyn framework had provided him with the flexibility, scalability, and performance needed to create an effective crime-fighting application, giving him a technological edge in his ongoing battle to protect Gotham City.
What's next?
Batman - Thanks, Robyn. Now tell me more. Robyn - Let us learn about the Middlewares and events now!