I have a small code serving 2 pages and a 404 error page :
from http.server import BaseHTTPRequestHandler, HTTPServer
import time
hostName = "localhost"
serverPort = 8069
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
suitFlag = 0
if self.path == '/':
self.path = '/index.html'
suitFlag = 1
try:
file_to_open = open(self.path[1:]).read()
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(bytes(file_to_open, 'utf-8'))
except:
self.send_response(404)
self.send_header('Content-type', 'text/html')
self.end_headers()
file_to_send = open('sadly404.html').read()
self.wfile.write(bytes(file_to_send, 'utf-8'))
if self.path == '/dashboard':
self.path = '/revenue.html'
suitFlag = 1
try:
file_to_open = open(self.path[1:]).read()
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(bytes(file_to_open, 'utf-8'))
except:
self.send_response(404)
self.send_header('Content-type', 'text/html')
self.end_headers()
file_to_send = open('sadly404.html').read()
self.wfile.write(bytes(file_to_send, 'utf-8'))
Now I want someone to visit /someHash/dashboard, I want to check from this code what the someHash is and then deliver relevant HTML page accordingly.
How can I do it?
I tried to use queryParams, but they can are not a feature I want to use to simplify my use case, These will be emmployees and they might be uncomfortable.
I want this someHash to be a part of URL not the query