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

add ssl keyfile and certfile #2706

Merged
merged 2 commits into from
Feb 10, 2025
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
27 changes: 18 additions & 9 deletions g4f/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,27 +629,36 @@ def run_api(
debug: bool = False,
workers: int = None,
use_colors: bool = None,
reload: bool = False
reload: bool = False,
ssl_keyfile: str = None,
ssl_certfile: str = None
) -> None:
print(f'Starting server... [g4f v-{g4f.version.utils.current_version}]' + (" (debug)" if debug else ""))

if use_colors is None:
use_colors = debug

if bind is not None:
host, port = bind.split(":")

if port is None:
port = DEFAULT_PORT

if AppConfig.demo and debug:
method = "create_app_with_demo_and_debug"
elif AppConfig.gui and debug:
method = "create_app_with_gui_and_debug"
else:
method = "create_app_debug" if debug else "create_app"

uvicorn.run(
f"g4f.api:{method}",
host=host,
port=int(port),
workers=workers,
use_colors=use_colors,
factory=True,
reload=reload
)
f"g4f.api:{method}",
host=host,
port=int(port),
workers=workers,
use_colors=use_colors,
factory=True,
reload=reload,
ssl_keyfile=ssl_keyfile,
ssl_certfile=ssl_certfile
)
8 changes: 7 additions & 1 deletion g4f/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def get_api_parser():
default=[], help="List of browsers to access or retrieve cookies from. (incompatible with --reload and --workers)")
api_parser.add_argument("--reload", action="store_true", help="Enable reloading.")
api_parser.add_argument("--demo", action="store_true", help="Enable demo mode.")

api_parser.add_argument("--ssl-keyfile", type=str, default=None, help="Path to SSL key file for HTTPS.")
api_parser.add_argument("--ssl-certfile", type=str, default=None, help="Path to SSL certificate file for HTTPS.")

return api_parser

def main():
Expand Down Expand Up @@ -68,7 +72,9 @@ def run_api_args(args):
debug=args.debug,
workers=args.workers,
use_colors=not args.disable_colors,
reload=args.reload
reload=args.reload,
ssl_keyfile=args.ssl_keyfile,
ssl_certfile=args.ssl_certfile
)

if __name__ == "__main__":
Expand Down
Loading