diff options
| author | UltraQbik <no1skill@yandex.ru> | 2024-08-26 01:13:11 +0300 |
|---|---|---|
| committer | UltraQbik <no1skill@yandex.ru> | 2024-08-26 01:13:11 +0300 |
| commit | 9b33b1622fcdfa9eb7eae21e26790732b262970c (patch) | |
| tree | eca3bec3cfd0e1236e258c4a9f88531690c369f8 | |
| parent | 7ff1a9756d6ecd86699cfbf0a8a3c72eec6fc8e9 (diff) | |
| download | httpy-9b33b1622fcdfa9eb7eae21e26790732b262970c.tar.gz httpy-9b33b1622fcdfa9eb7eae21e26790732b262970c.zip | |
Update init_path_map function
| -rw-r--r-- | main.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/main.py b/main.py index c7c2f81..715513e 100644 --- a/main.py +++ b/main.py @@ -27,9 +27,9 @@ path_map = { "/about": {"path": "www/about.html"}, "/test": {"path": "www/test.html"}, "/projects": {"path": "www/projects.html"}, - "/images/*": {"path": "www/images"}, + "/images/*": {"path": "www/images/"}, "/js-test": {"path": "www/js-test.html"}, - "/scripts/*": {"path": "www/scripts"}, + "/scripts/*": {"path": "www/scripts/"}, } # API @@ -50,11 +50,14 @@ def init_path_map(verbose: bool = False): for key in list(path_map.keys()): if key[-1] == "*": - for file in os.listdir(path_map[key]["path"]): - new_path = f"{key[:-2]}/{file}" - new_redirect_path = f"{path_map[key]['path']}/{file}" - path_map[new_path] = {"path": new_redirect_path} - path_map.pop(key) + try: + for file in os.listdir(path_map[key]["path"]): + new_path = f"{key[:-1]}{file}" + new_redirect_path = f"{path_map[key]['path']}{file}" + path_map[new_path] = {"path": new_redirect_path} + path_map.pop(key) + except FileNotFoundError: + print(f"Unable to find '{path_map[key]["path"]}'") if verbose: print("LIST OF ALLOWED PATHS:") max_len = max([len(x) for x in path_map.keys()]) + 2 |