| 9 | FOLDER = '.' if len(sys.argv) < 2 else sys.argv[1] |
| 10 | |
| 11 | def get_content(path): |
| 12 | ext = "html" |
| 13 | if path == "/": |
| 14 | try: |
| 15 | with open(FOLDER + "/index.html", "r") as f: |
| 16 | content = f.read() |
| 17 | except FileNotFoundError: |
| 18 | content = "The Server is working! but there is no index.html file to render" |
| 19 | else: |
| 20 | try: |
| 21 | with open(FOLDER + path, "r") as f: |
| 22 | if Path(FOLDER + path).suffix != ".html": |
| 23 | ext = "plain" |
| 24 | content = f.read() |
| 25 | except FileNotFoundError: |
| 26 | return 404, "File not found", ext |
| 27 | return 200, content, ext |
| 28 | |
| 29 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: |
| 30 | try: |