Sets up the runtime config for the web server.
(self, web_assets_dir: str)
| 795 | return getattr(module, obj_name) |
| 796 | |
| 797 | def _setup_runtime_config(self, web_assets_dir: str): |
| 798 | """Sets up the runtime config for the web server.""" |
| 799 | # Read existing runtime config file. |
| 800 | runtime_config_path = os.path.join( |
| 801 | web_assets_dir, "assets", "config", "runtime-config.json" |
| 802 | ) |
| 803 | runtime_config = {} |
| 804 | try: |
| 805 | with open(runtime_config_path, "r") as f: |
| 806 | runtime_config = json.load(f) |
| 807 | except FileNotFoundError: |
| 808 | logger.info( |
| 809 | "File not found: %s. A new runtime config file will be created.", |
| 810 | runtime_config_path, |
| 811 | ) |
| 812 | except json.JSONDecodeError: |
| 813 | logger.warning( |
| 814 | "Failed to decode JSON from %s. The file content will be" |
| 815 | " overwritten.", |
| 816 | runtime_config_path, |
| 817 | ) |
| 818 | runtime_config["backendUrl"] = self.url_prefix if self.url_prefix else "" |
| 819 | |
| 820 | # Set custom logo config. |
| 821 | if self.logo_text or self.logo_image_url: |
| 822 | if not self.logo_text or not self.logo_image_url: |
| 823 | raise ValueError( |
| 824 | "Both --logo-text and --logo-image-url must be defined when using" |
| 825 | " logo config." |
| 826 | ) |
| 827 | runtime_config["logo"] = { |
| 828 | "text": self.logo_text, |
| 829 | "imageUrl": self.logo_image_url, |
| 830 | } |
| 831 | elif "logo" in runtime_config: |
| 832 | del runtime_config["logo"] |
| 833 | |
| 834 | # Write the runtime config file. |
| 835 | try: |
| 836 | os.makedirs(os.path.dirname(runtime_config_path), exist_ok=True) |
| 837 | with open(runtime_config_path, "w") as f: |
| 838 | json.dump(runtime_config, f, indent=2) |
| 839 | f.write("\n") |
| 840 | except IOError as e: |
| 841 | logger.error( |
| 842 | "Failed to write runtime config file %s: %s", runtime_config_path, e |
| 843 | ) |
| 844 | |
| 845 | async def _create_session( |
| 846 | self, |