Skip to content

Commit ac648fd

Browse files
authored
feat(api): add API server config block (#44)
We introduce an explicit server config block and environment variables for; 1. API server port `NESIS_API_SERVER_PORT` 2. API server listen address `NESIS_API_SERVER_ADDRESS` This is to allow easier configuration during deployment via environment variables of config yaml. Part of #25
1 parent df35d13 commit ac648fd

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

nesis/api/core/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
from tzlocal import get_localzone
33

44
default = {
5+
"server": {
6+
"port": os.environ.get("NESIS_API_SERVER_PORT", "6000"),
7+
"address": os.environ.get("NESIS_API_SERVER_ADDRESS", "0.0.0.0"),
8+
},
59
"database": {
610
"url": os.environ.get("NESIS_API_DATABASE_URL"),
7-
"debug": False,
11+
"debug": os.environ.get("NESIS_API_DATABASE_DEBUG", False),
812
"create": False,
913
},
1014
"tasks": {

nesis/api/core/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def run_cloud(app, args, services):
3737
config = {}
3838

3939
config = util.merge(config, settings.default)
40-
service_config = config.get("service") or {}
40+
service_config = config.get("server") or {}
4141

4242
# Initialize database
4343
try:
@@ -59,10 +59,10 @@ def run_cloud(app, args, services):
5959
sys.exit(1)
6060

6161
# Start the application
62-
port = service_config.get("port", os.environ.get("NESIS_API_PORT")) or "6000"
63-
host = service_config.get("host") or "0.0.0.0"
62+
port = service_config["port"]
63+
address = service_config["address"]
6464

65-
http_server = WSGIServer((host, int(port)), cloud_ctrl.app)
65+
http_server = WSGIServer((address, int(port)), cloud_ctrl.app)
6666

6767
_LOG.info("Starting server...")
6868
http_server.serve_forever()

0 commit comments

Comments
 (0)