Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ssl support using custom key/cert files #1047

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion backend/chainlit/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def run_chainlit(target: str):
host = os.environ.get("CHAINLIT_HOST", DEFAULT_HOST)
port = int(os.environ.get("CHAINLIT_PORT", DEFAULT_PORT))

ssl_certfile = os.environ.get("CHAINLIT_SSL_CERT", None)
ssl_keyfile = os.environ.get("CHAINLIT_SSL_KEY", None)

ws_per_message_deflate_env = os.environ.get(
"UVICORN_WS_PER_MESSAGE_DEFLATE", "true"
)
Expand Down Expand Up @@ -75,6 +78,8 @@ async def start():
port=port,
log_level=log_level,
ws_per_message_deflate=ws_per_message_deflate,
ssl_keyfile=ssl_keyfile,
ssl_certfile=ssl_certfile,
)
server = uvicorn.Server(config)
await server.serve()
Expand Down Expand Up @@ -126,13 +131,34 @@ async def start():
envvar="NO_CACHE",
help="Useful to disable third parties cache, such as langchain.",
)
@click.option(
"--ssl-cert",
default=None,
envvar="CHAINLIT_SSL_CERT",
help="Specify the file path for the SSL certificate.",
)
@click.option(
"--ssl-key",
default=None,
envvar="CHAINLIT_SSL_KEY",
help="Specify the file path for the SSL key",
)
@click.option("--host", help="Specify a different host to run the server on")
@click.option("--port", help="Specify a different port to run the server on")
def chainlit_run(target, watch, headless, debug, ci, no_cache, host, port):
def chainlit_run(
target, watch, headless, debug, ci, no_cache, ssl_cert, ssl_key, host, port
):
if host:
os.environ["CHAINLIT_HOST"] = host
if port:
os.environ["CHAINLIT_PORT"] = port
if bool(ssl_cert) != bool(ssl_key):
raise click.UsageError(
"Both --ssl-cert and --ssl-key must be provided together."
)
if ssl_cert:
os.environ["CHAINLIT_SSL_CERT"] = ssl_cert
os.environ["CHAINLIT_SSL_KEY"] = ssl_key
if ci:
logger.info("Running in CI mode")

Expand All @@ -150,6 +176,8 @@ def chainlit_run(target, watch, headless, debug, ci, no_cache, host, port):
config.run.no_cache = no_cache
config.run.ci = ci
config.run.watch = watch
config.run.ssl_cert = ssl_cert
config.run.ssl_key = ssl_key

run_chainlit(target)

Expand Down
2 changes: 2 additions & 0 deletions backend/chainlit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class RunSettings:
module_name: Optional[str] = None
host: str = DEFAULT_HOST
port: int = DEFAULT_PORT
ssl_cert: Optional[str] = None
ssl_key: Optional[str] = None
headless: bool = False
watch: bool = False
no_cache: bool = False
Expand Down
Loading