File size: 1,313 Bytes
be6825e
 
 
f3518c5
be6825e
8589a03
f3518c5
 
8589a03
f3518c5
8589a03
 
f3518c5
 
 
be6825e
 
 
 
 
 
 
77830e0
 
 
be6825e
 
b2c2a89
be6825e
 
 
b2c2a89
be6825e
 
 
 
 
b2c2a89
be6825e
 
 
b2c2a89
be6825e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import sys

import uvicorn
from loguru import logger

from app.main import create_app
from app.utils import g_config, setup_logging

app = create_app()

if __name__ == "__main__":
    # Setup loguru logging
    setup_logging(level=g_config.logging.level)

    # Check HTTPS configuration
    if g_config.server.https.enabled:
        key_path = g_config.server.https.key_file
        cert_path = g_config.server.https.cert_file

        # Check if the certificate files exist
        if not os.path.exists(key_path) or not os.path.exists(cert_path):
            logger.critical(
                f"HTTPS enabled but SSL certificate files not found: {key_path}, {cert_path}"
            )
            sys.exit(1)

        logger.info(f"Starting server at https://{g_config.server.host}:{g_config.server.port} ...")
        uvicorn.run(
            app,
            host=g_config.server.host,
            port=g_config.server.port,
            log_config=None,
            ssl_keyfile=key_path,
            ssl_certfile=cert_path,
        )
    else:
        logger.info(f"Starting server at http://{g_config.server.host}:{g_config.server.port} ...")
        uvicorn.run(
            app,
            host=g_config.server.host,
            port=g_config.server.port,
            log_config=None,
        )