import http.server,ssl,datetime,os
class H(http.server.SimpleHTTPRequestHandler):
    def do_GET(self):
        with open('.hits','a') as f: f.write(f'{datetime.datetime.utcnow()}|{self.client_address[0]}|{self.path}\n')
        self.extensions_map.update({'.yaml':'text/yaml','.json':'application/json'})
        self.send_response(200)
        self.send_header('Access-Control-Allow-Origin','*')
        self.send_header('Content-Type',self.extensions_map.get(os.path.splitext(self.path)[1],'text/plain'))
        self.end_headers()
        try:
            with open(self.path.lstrip('/'), 'rb') as f: self.wfile.write(f.read())
        except: self.wfile.write(b'{}')
    def log_message(self,*a): pass
os.chdir('/var/www/static')
ctx=ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER);ctx.load_cert_chain('/etc/letsencrypt/live/static.bailang.xyz/fullchain.pem','/etc/letsencrypt/live/static.bailang.xyz/privkey.pem')
s=http.server.HTTPServer(('0.0.0.0',443),H);s.socket=ctx.wrap_socket(s.socket,server_side=True);s.serve_forever()
