(self, path: str = "config_webserver.yaml")
| 353 | ) |
| 354 | |
| 355 | def load_webserver_config(self, path: str = "config_webserver.yaml"): |
| 356 | # Build the full path to the config file using the config directory |
| 357 | full_path = os.path.join(self.config_directory, path) |
| 358 | |
| 359 | try: |
| 360 | with open(full_path) as f: |
| 361 | data = yaml.safe_load(f) |
| 362 | except FileNotFoundError: |
| 363 | # If config file doesn't exist, use defaults |
| 364 | print(f"Warning: {path} not found. Using default webserver configuration.") |
| 365 | data = { |
| 366 | "port": 8080, |
| 367 | "static_directory": "./static", |
| 368 | "homepage": "static/index.html", |
| 369 | "server": {} |
| 370 | } |
| 371 | |
| 372 | # Load basic configurations with the new method |
| 373 | self.port: int = self._get_config_value(data.get("port"), 8080) |
| 374 | self.static_directory: str = self._get_config_value(data.get("static_directory"), "./static") |
| 375 | self.mode: str = self._get_config_value(data.get("mode"), "production") |
| 376 | self.homepage: str = self._get_config_value(data.get("homepage"), "static/index.html") |
| 377 | self.nlweb_gateway: str = self._get_config_value(data.get("nlweb_gateway"), "nlwm.azurewebsites.net") |
| 378 | |
| 379 | # Keep static directory relative to config directory, not base output directory |
| 380 | if not os.path.isabs(self.static_directory): |
| 381 | self.static_directory = os.path.abspath(os.path.join(self.config_directory, self.static_directory)) |
| 382 | |
| 383 | # Load server configurations |
| 384 | server_data = data.get("server", {}) |
| 385 | |
| 386 | # SSL configuration |
| 387 | ssl_data = server_data.get("ssl", {}) |
| 388 | ssl_config = SSLConfig( |
| 389 | enabled=self._get_config_value(ssl_data.get("enabled"), False), |
| 390 | cert_file=self._get_config_value(ssl_data.get("cert_file_env")), |
| 391 | key_file=self._get_config_value(ssl_data.get("key_file_env")) |
| 392 | ) |
| 393 | |
| 394 | # Logging configuration |
| 395 | logging_data = server_data.get("logging", {}) |
| 396 | logging_file = self._get_config_value(logging_data.get("file"), "./logs/webserver.log") |
| 397 | # Use the _resolve_path method for logging file (but not for static directory) |
| 398 | logging_file = self._resolve_path(logging_file) |
| 399 | |
| 400 | logging_config = LoggingConfig( |
| 401 | level=self._get_config_value(logging_data.get("level"), "info"), |
| 402 | file=logging_file |
| 403 | ) |
| 404 | |
| 405 | # Static file configuration |
| 406 | static_data = server_data.get("static", {}) |
| 407 | static_config = StaticConfig( |
| 408 | enable_cache=self._get_config_value(static_data.get("enable_cache"), True), |
| 409 | cache_max_age=self._get_config_value(static_data.get("cache_max_age"), 3600), |
| 410 | gzip_enabled=self._get_config_value(static_data.get("gzip_enabled"), True) |
| 411 | ) |
| 412 |
no test coverage detected