Add index page for PyFiche Lines server

Implemented a welcoming index page for the PyFiche Lines HTTP server. Now, when users access the root URL, they are greeted with an informative page that includes a brief introduction to the service, its purpose, and a link to the project's repository for additional information. This enhancement improves user experience by providing context and guidance for new visitors to the server.
This commit is contained in:
Kumi 2024-01-22 08:39:37 +01:00
parent b99ea03635
commit 80d5aad05d
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -46,6 +46,13 @@ body {{
</html> </html>
""" """
INDEX_CONTENT = BASE_HTML.format(
content="""<h1>PyFiche Lines</h1>
<p>Welcome to PyFiche Lines, a HTTP server for PyFiche.</p>
<p>PyFiche Lines is a HTTP server for PyFiche. It allows you to view files uploaded through PyFiche in your browser.</p>
<p>For more information, see <a href="https://kumig.it/PrivateCoffee/pyfiche">the PyFiche Git repo</a>.</p>"""
)
server_version = "PyFiche Lines/dev" server_version = "PyFiche Lines/dev"
def do_POST(self): def do_POST(self):
@ -162,6 +169,16 @@ body {{
url = urlparse(self.path.rstrip("/")) url = urlparse(self.path.rstrip("/"))
# If the URL is /, display the index page
if url.path == "/":
self.send_response(200)
self.send_header("Content-Type", "text/html")
self.send_header("Content-Length", len(self.INDEX_CONTENT))
self.end_headers()
self.wfile.write(self.INDEX_CONTENT.encode("utf-8"))
return
# Discard any URLs that aren't of the form /<slug> or /<slug>/raw # Discard any URLs that aren't of the form /<slug> or /<slug>/raw
if not len(url.path.split("/")) in [2, 3]: if not len(url.path.split("/")) in [2, 3]:
return self.not_found() return self.not_found()