jukebox-software/fileserver.py

17 lines
473 B
Python

import http.server
import socketserver
import os
def run_server(port, directory):
"""
Run a simple HTTP server serving files from the specified directory.
"""
# Change the working directory to the specified directory
os.chdir(directory)
# Create the HTTP server
handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", port), handler) as httpd:
print(f"Serving at port {port}")
httpd.serve_forever()