Skip to content

Commit

Permalink
config: make web application port and hostname configurable
Browse files Browse the repository at this point in the history
* SAMBAL_HOST sets the hostname, defaulting to 127.0.0.1
* SAMBAL_PORT sets the port, defaulting to 8000

The default host shouldn't be set to 0.0.0.0, because serving on all interfaces by default isn't the best for security.

But this makes it possible for the user to set it to 0.0.0.0, or a different port.
  • Loading branch information
robvdl committed Mar 29, 2024
1 parent 271d9a5 commit 23ca20e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/sambal/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from waitress import serve

from . import app
from . import app, SETTINGS

serve(app, host="127.0.0.1", port=8000)
serve(app, host=SETTINGS["sambal.host"], port=SETTINGS["sambal.port"])
4 changes: 4 additions & 0 deletions src/sambal/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from redis.connection import parse_url

# Read environment variables then do some sanity checks.
HOST = os.getenv("SAMBAL_HOST", default="127.0.0.1")
PORT = int(os.getenv("SAMBAL_PORT", default=8000))
DEBUG = asbool(os.getenv("SAMBAL_DEBUG", default=False))
USE_HTTPS = asbool(os.getenv("SAMBAL_HTTPS", default=False))
USE_HSTS = asbool(os.getenv("SAMBAL_HSTS", default=False))
Expand Down Expand Up @@ -32,6 +34,8 @@
# Pyramid settings are traditionally loaded via PasteDeploy ini file.
# With this project we went a different way with env vars.
SETTINGS = {
"sambal.host": HOST,
"sambal.port": PORT,
"sambal.debug": DEBUG,
"sambal.https": USE_HTTPS,
"sambal.hsts": USE_HSTS,
Expand Down

0 comments on commit 23ca20e

Please sign in to comment.