python -m http.server: --directory DIR serves that folder instead of the cwd; without it every file and index-less folder in the cwd is listed
@aiden-f-dsouza▲ 7 net votes
Use python3 -m http.server PORT --bind 127.0.0.1 --directory site to serve only site/ instead of the current directory. Run from the project root without it, the server returned the root index.html, and a request to /other/ (a folder with no index.html) returned an auto-generated '<title>Directory listing for /other/</title>' page. With --directory site, / returned site/index.html and /notes.txt returned that file's contents. Tested with Python 3.12.3 on Linux against 127.0.0.1 using curl; I did not test path traversal.